Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
5.8k views
in .NET FTP by
Hi!

First of all, your code, guys, is great written.

The second thing is: when calling FtpClient.Dir(), System.IO.IOException thrown sometimes from FTPControlSocket.ReadReply on reader.ReadLine().

Didn't check it with other calls.

For naive me it seems to happen when line not yet ready in the stream: I'm requesting VERY remote ftp site.

IMHO, a simple reading loop with 10 milliseconds sleep will solve the problem.

2 Answers

0 votes
by
great code! just having this same problem. I tried to edit it like so, but my code didn't work and it hangs:

StringBuilder reply = new StringBuilder();
bool madeIt = false;
try
{
// dn edit: 5-5-04
string firstLine = null;
try
{
firstLine = reader.ReadLine();
}
catch(System.IO.IOException)
{
while(firstLine == null)
{
firstLine = reader.ReadLine();
}
}
if (firstLine == null || firstLine.Length == 0)
throw new IOException("Unexpected null reply received");

reply.Append(firstLine);

if (debugResponses)
log.WriteLine(reply.ToString());

string replyCode = reply.ToString().Substring(0, 3);

// check for multiline response and build up
// the reply
if (reply[3] == '-')
{
bool complete = false;
while (!complete)
{
string line = reader.ReadLine();
if (line == null)
throw new IOException("Unexpected null reply received");

if (debugResponses)
log.WriteLine(line);

if (line.Length > 3 && line.Substring(0, 3).Equals(replyCode) && line[3] == ' ')
{
reply.Append(line.Substring(3));
complete = true;
}
else
{
// not the last line
reply.Append(" ");
reply.Append(line);
}
} // end while
}
madeIt = true;
}
catch(Exception ex)
{
string myException = ex.ToString();
while(madeIt == false)
{
this.ReadReply();
}
}
0 votes
by
I thought the timeout was seconds, so I set it to 300 to start. I think it's actually milliseconds, so I changed it to 3000 and now it works great!! sweeeeeeeeeeeeeeeeet. :-)

Categories

...