Our Products:   CompleteFTP  edtFTPnet/Free  edtFTPnet/PRO  edtFTPj/Free  edtFTPj/PRO
0 votes
11.7k views
in .NET FTP by (740 points)
Hi,

I am in a testing mode. To test my program I am using Qick 'n Easy FTP Server 3.1 Lite [1]. When connecting the timeout does not get thrown clientsided with using the edtFTPnet Version 1.2.6.0.

When the server cut of the connection my .NET program still provides a "IsConnected" == true, but when I like to close the connection a SocketException is thrown because the serverside already disconnected the my client.

Here is the code I use:

        public void Close()
        {
            foreach (FTPConnection connection in connections.Values)
                if (connection.IsConnected)
                    connection.Close();
        }



I expect a disconnecting event when the server cuts of the connection. Shouldn't it do so???

Robert.



PS: I can not send any images, because your imageserver are blocked out of my companies firewall I am working for.


[1] http://www.pablosoftwaresolutions.com/h ... erver.html

17 Answers

0 votes
by (740 points)
You can not receive Socket Termination because u use Synchronous Sockets. Is that right?
0 votes
by (162k points)
The server has disconnected the client because of its timeout. The client can't know about this until the next read or write attempt.
0 votes
by (740 points)
The server has disconnected the client because of its timeout. The client can't know about this until the next read or write attempt.


Hm, because of that, I have to write a try/catch around each io-command? Is there no TCP/Socket option to catch the signal? Could you not use async- Sockets via select(...)?

Rov.
0 votes
by (162k points)
Every FTP command can throw an FTPException or an IOException.

It simply isn't possible for a client to detect all instances when a server might have gone away - even Select() can't do that.

If the server is timing out the client, set the idle timeout to be 30s - if you want to stay connected.

Normally with FTP, it is best to login, do your stuff and logout. Maintaining a connection is not a good idea.
0 votes
by (740 points)
Every FTP command can throw an FTPException or an IOException.
Normally with FTP, it is best to login, do your stuff and logout. Maintaining a connection is not a good idea.


Tell this my hundred users!!! Is there no way to get around this. How do other people work out this problem?

How have you done it within your dialogs? Do you catch all Exceptions? Doesn't that make the code a lot harder too read?

Rov.
0 votes
by (162k points)
It is no different to using a socket, basically, or even a database connection.

Catching exceptions doesn't necessarily make the code hard to read - you can put a try/catch block around a number of method calls, e.g.

try {
ftp.Connect();
ftp.ChangeDirectory("abc");
ftp.Upload ...
ftp.Download ....
....
}
catch (FTPException e) {
// report or flag error
}
catch (IOException e) {
// report or flag error
}
finally {
// disconnect?
}
0 votes
by (740 points)
It is no different to using a socket, basically, or even a database connection.

Catching exceptions doesn't necessarily make the code hard to read - you can put a try/catch block around a number of method calls, e.g.

try {
ftp.Connect();
ftp.ChangeDirectory("abc");
ftp.Upload ...
ftp.Download ....
....
}
catch (FTPException e) {
// report or flag error
}
catch (IOException e) {
// report or flag error
}
finally {
// disconnect?
}


I have FTPDirectoryListing Dialog. So this one requires at a certain time a connect to the server. To another time it requires a login, later on a list, later on a download, ...

So all commands are triggered by the user as he clicks on a button. Therefore I need to try/catch all these commands. I surely have to do that still to catch the any exception. But how do you manage terminations/disconnects by the server. Do let the user ran into this trouble? In this case I would like to bring my dialog into a consistent state and clean up all my connections but I can't.

Regards,
Rov.

Categories

...