Re: Timeout Property - WeOnlyDo Discussion board

Re: Timeout Property (General questions)

by kdcarlisle, Monday, July 06, 2009, 22:06 (5401 days ago) @ kdcarlisle

Drazen,

I created a simple standalone app that will test the basics of our powershell snap-in. I have run this code with both versions (1.4.3 and 1.4.5) of the compoent. While they both work (most of the time), there are some differences.

1) The 1.4.3 version will time-out (randomly) on the ftp.ListNames line.
2) The 1.4.5 version will break (randomly) on the (a) using (StreamReader sr = new StreamReader(ms)) and (b) while (sr.Peek() > 0) lines. When I say break, I mean that the debugger just drops out of the method without throwing an exception.

Here is the code that is being used in the sample application.

-Kent

FtpDLX ftp = null;

try {

ftp = new FtpDLX();

ftp.Authentication = Authentications.Password;
ftp.Hostname = txtServer.Text;
ftp.Login = txtAccountName.Text;
ftp.Password = txtAccountPassword.Text;
ftp.TransferMode = TransferModes.Binary;
ftp.LicenseKey = ???????? ;
ftp.Blocking = true;
ftp.StrictHost = true;
ftp.Passive = false;

ftp.Protocol = Protocols.FTP;

ftp.Timeout = 150;

ftp.Connect();

List<string> lst = new List<string>();

using (MemoryStream ms = new MemoryStream()) {

ftp.ListNames(txtLocation.Text, ms);

if (ftp.LastError != null) throw ftp.LastError;

ms.Seek(0, SeekOrigin.Begin);

using (StreamReader sr = new StreamReader(ms)) {

while (sr.Peek() > 0) {

string tmpFileName = sr.ReadLine();

MessageBox.Show( File: + tmpFileName);

if (!tmpFileName.StartsWith( . ) && !tmpFileName.EndsWith( / ) && Utils.FilePatterns.IsMatch(tmpFileName, txtPattern.Text)) lst.Add(tmpFileName);

}

}

}

for (int i = 0; i < lst.Count; i++) {

string localFile = Path.Combine(txtDownloadTo.Text, lst);
string remoteFile = string.Format( {0}/{1} , txtLocation.Text, lst);

MessageBox.Show( Downloading: + remoteFile);

ftp.GetFile(txtDownloadTo.Text, remoteFile);

MessageBox.Show( Fetched: + lst);

}

} catch (Exception ex) {

MessageBox.Show(ex.Message);

} finally {

if (ftp != null) {

try { if (ftp.State != States.Disconnected) ftp.Disconnect(); } catch { }
try { ftp.Dispose(); } catch { }

}

}


Complete thread: