No folder content returned by either GetFiles or GetItems

No folder content returned by either GetFiles or GetItems

Hi. I am using Xceed FTP Version latest version (evaluation).

I am
getting FTP Timeout Exception in some cases, but the exception does not occur
within the ‘normal’ sequence of the code, so it cannot be caught and handled,
and it is causing the application to crash.

the application connects to
multiple FTP sites, and gets the first file name found per each site (it
doesn’t even perform a download). Everything is warped in a try-catch, but as
I said before, the exception is thrown out of this loop.

 

Exception: FtpTimeoutException

Message: The FTP command execution timed-out.

StackTrace: at
Xceed.Ftp.Engine.FtpCommand.OnCommandTimeout(Object state, Boolean timedOut) at
System.Threading._ThreadPoolWaitOrTimerCallback.WaitOrTimerCallback_Context_t(Object
state) at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state) at
System.Threading._ThreadPoolWaitOrTimerCallback.PerformWaitOrTimerCallback(Object
state, Boolean timedOut)

 

The main issue is that the exception can’t be caught.
if there a thread being initiated what performing the login/getFolderContent
process? how come exception does not occur within my code, rather than from a
different thread? We have found a thread with having the same problem exactly:

http://xceed.com/CS/forums/thread/23648.aspx

and this didn’t seems to be resolved eventually.

Please advise. thanks!

 Code sample if

needed:

 

using System; using System.Collections.Generic; using System.Text;
using Xceed.Ftp; namespace WindowsFormsApplication1 { public class FTPMethods {
public static void TestFTPSites() { List < FtpInfoObject > ftpSites = new
List < FtpInfoObject >(); /**** * Add FTP Sites from a database… *
*****/ StringBuilder messages = new StringBuilder (); List < string >
files = new List < string >(); foreach ( FtpInfoObject fio in ftpSites) {
string error; FtpClient ftpClient = CreateLoggedInInstance(fio, out error);
bool hasConnection = ftpClient != null && ftpClient.Connected
&& string .IsNullOrEmpty(error); if (hasConnection) { string fileName;
try { fileName = GetFTPInfoOneObject(ftpClient, fio.StartupFolder, messages);
files.Add(fileName); } catch ( Exception exc) { /*** REPORT ON ERROR WHEN
DOWNLOADING FTP FILE ****/ } } else { // Error on connection! /*** REPORT ON A
FAILURE IN CONNECTION ****/ } try { if (ftpClient.Connected) {
ftpClient.Disconnect(); } } catch ( Exception exc) { /*** REPORT ON EXCEPTION
WHILE PERFORMING FTP DOWNLOAD ****/ } } } private static string
GetFTPInfoOneObject( FtpClient client, string targetFolder, StringBuilder
message) { try { client.ChangeCurrentFolder(targetFolder); } catch { if
(message != null ) message.AppendLine( “Unable to find folder ‘” +
targetFolder + “‘” ); return “” ; } FtpItemInfoList
allFiles = null ; try { allFiles = client.GetFolderContents(); } catch ( FtpReplyException
ftpREXC) { message.AppendLine( “FTP get folder contents FtpReplyException:
‘” + targetFolder + “‘ ” + ftpREXC.Message); if
(ftpREXC.Reply.ReplyCode != 550) throw ftpREXC; } catch (
FtpInvalidStateException ftpTimeOut) { message.AppendLine( “FTP get folder
contents FtpInvalidStateException: ‘” + targetFolder + “‘ ” +
ftpTimeOut.Message); return “” ; } catch ( Exception genExc) {
message.AppendLine( “FTP get folder contents Exception: ‘” +
targetFolder + “‘ ” + genExc.Message); return “” ; } if
(allFiles.Count == 0) return “” ; else return allFiles[0].Name; }
public static bool ConnectFtp( FtpClient ftpClient, string ftpHost, bool
useSsl, bool isPassive) { // Connect: string url = ftpHost.ToLower().Replace(
ftp://&#8221; , “” ).Replace( “ftp:\\” , “”
); int port = 21; // Get the port, if defined: if (url.Contains( “:”
)) { string [] words = url.Split( ‘:’ ); url = words[0]; bool parsed = int
.TryParse(words[words.Length – 1], out port); } url = url.TrimStart( ‘\\’ , ‘/’
); ftpClient.Connect(url, port); ftpClient.PassiveTransfer = isPassive;
ftpClient.UseRemoteAddress = true ; if (useSsl) { ftpClient.Authenticate(
AuthenticationMethod .Ssl, VerificationFlags .None, null ,
DataChannelProtection .Private); } return true ; } public static FtpClient CreateLoggedInInstance(
FtpInfoObject ftpInfo, out string error) { error = “” ; Licenser
.LicenseKey = “FTN40-NFW4T-1UYTY-9NJA” ; FtpClientExtended ftpClient
= new FtpClientExtended (); ftpClient.KeepAliveInterval = 900; bool
hasConnection = false ; // Try to connect, using a secured connection: try {
hasConnection = ConnectFtp(ftpClient, ftpInfo.IPAddress, ftpInfo.IsSecured,
ftpInfo.IsPassive); } catch ( Exception exc) { error = “Failed to connect.
” + exc.Message; try { ftpClient.Disconnect(); } catch { } } try { if
(hasConnection) { ftpClient.Login(ftpInfo.UserName, ftpInfo.Password); } }
catch ( Exception exc) { error = “Failed performing login. ” +
exc.Message; hasConnection = false ; } if (hasConnection) { //set root folder
as the current folder after log-in ftpClient.RootFolder =
ftpClient.GetCurrentFolder(); //set startup folder if set if (! string
.IsNullOrEmpty(ftpInfo.StartupFolder)) { try {
ftpClient.ChangeCurrentFolder(ftpInfo.StartupFolder.TrimStart( “~/”
.ToCharArray())); } catch { error = “Failed to change working directory to
” + ftpInfo.StartupFolder; ftpClient.Disconnect(); } } } else { if
(ftpClient.Connected) ftpClient.Disconnect(); } ftpClient.CertificateReceived
+= new CertificateReceivedEventHandler (ftpClient_CertificateReceived); return
ftpClient; } private static void ftpClient_CertificateReceived( object sender,
CertificateReceivedEventArgs e) { e.Action = VerificationAction .Accept; } }
///

/// ///

public class FtpClientExtended : FtpClient {
public string RootFolder { get ; set ; } } ///

/// ///

public
class FtpInfoObject { ///

/// ///

public FtpInfoObject() { }
public string IPAddress { get ; set ; } public string UserName { get ; set ; }
public string Password { get ; set ; } public bool IsSecured { get ; set ; }
public bool IsPassive { get ; set ; } public string StartupFolder { get ; set ;
} public string ParsePatterns { get ; set ; } public string SUSOverrideUser {
get ; set ; } public DateTime SUSOverrideDate { get ; set ; } public bool
IsDefaultValues { get ; set ; } public bool IsFileSystem { get ; set ; } public
string Name { get ; set ; } public string Description { get ; set ; }
[System.Xml.Serialization. XmlIgnore ] public int ? ID { get ; set ; }
[System.Xml.Serialization. XmlIgnore ] public bool DirtyFlag { get ; set ; } } }