Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
3.9k views
in .NET FTP by
The following code never returns from the first line when I supply a non-existent IP. Needless to say this is deadly for my app and I need a timeout. Can I set a timeout before the FTPClient constructor?

FTPClient ftp = new FTPClient( "192.168.1.200" );
ftp.Timeout = 10;


Before I tried this EDT dll, I was using some homemade ftp code and it was hanging in a similar way at the dns.resolve call.

P.S. What are the units for the Timeout setting? I couldn't find it in the docs.

4 Answers

0 votes
by (161k points)
Use:

FTPClient ftp = new FTPClient();
ftp.RemoteHost = "192.168.1.200";
ftp.Timeout = 10000; // milliseconds
ftp.Connect();

The following code never returns from the first line when I supply a non-existent IP. Needless to say this is deadly for my app and I need a timeout. Can I set a timeout before the FTPClient constructor?

FTPClient ftp = new FTPClient( "192.168.1.200" );
ftp.Timeout = 10;


Before I tried this EDT dll, I was using some homemade ftp code and it was hanging in a similar way at the dns.resolve call.

P.S. What are the units for the Timeout setting? I couldn't find it in the docs.
0 votes
by
I tried using the code above...but I don't see anything happening when I provide a non-existent IP...that is when the timeout event happens...I would like to display a message to the user when the timeout happens...how can I use the Timeout property to do that?

Thanks.
0 votes
by (161k points)
Actually that timeout value won't work for what you are doing.

I tried using the code above...but I don't see anything happening when I provide a non-existent IP...that is when the timeout event happens...I would like to display a message to the user when the timeout happens...how can I use the Timeout property to do that?

Thanks.
0 votes
by (500 points)
Actually that timeout value won't work for what you are doing.

I tried using the code above...but I don't see anything happening when I provide a non-existent IP...that is when the timeout event happens...I would like to display a message to the user when the timeout happens...how can I use the Timeout property to do that?

Thanks.


Could you elaborate more on this? I actually have a valid IP to connect with, then unplug the connecting fiber. Will set timeout make an exception thrown?

(I tried to set 1, 2, 4 minutes. but only get a IOException after about 10 miuntes)

Maybe what you said is correct, but how to detect if fiber is unplugged, if setting timeout will not work?

Thanks !

Categories

...