Exception "Cannot send command to the server because the response for previous one was not received." is sometimes thrown by FTP library

+1 vote
asked Aug 17, 2012 by Rebex KB (8,190 points)
edited Aug 17, 2012

For instance, I just got it when trying to upload multiple files. The problem is that the Connected property is still true, but each operation I try to perform afterwards, for instance uploading the next file in the queue, gives me the same error.

My question is: How do I handle this? Do I need to re-connect? How do I detect it? Let me know how you propose that I deal with this in my FTP client.

Applies to: Rebex FTP/SSL

1 Answer

+1 vote
answered Aug 17, 2012 by Jan Sotola (16,920 points)
edited Aug 17, 2012
 
Best answer

This exception should only be thrown after a previous FtpException (representing the actual cause of the problem) was silently ignored.

The cause of the first exception is usually a timeout while waiting for the response of a command that the client sent to the FTP server. When a timeout or similar exception occurs, the Ftp object is most likely left in an unusable state because it has not received the response it was waiting for, and any attempt to send another command would most likely result in a similar problem. Therefore, if the application tries to issue another FTP command using an Ftp object in this state, we throw the exception you are seeing.

To handle this, detect the "bad" state of the Ftp object after catching the first FtpException that caused it - simply check whether Ftp object's State property is FtpState.Ready. If it's not, re-connect and try again.

It might also help to create a communication log using Ftp object's LogWriter property (as described at http://www.rebex.net/kb/logging/) - looking into the log, it should be easily possible to tell what is going on and what caused the bad state in the first place.

NOTE: Although reported as an error from the Rebex FTP/SSL component, the same exception can be also thrown from the SMTP, IMAP or POP3 components (parts of the Rebex Secure Mail package). A solution is the same there.

commented Mar 25, 2015 by ganeshspy (900 points)
any other solution for this type exception..
commented Mar 25, 2015 by Tomas Knopp (58,890 points)
Maybe, but we need to see the log of communication, so please create it using the LogWriter property as described at http://www.rebex.net/kb/logging/default.aspx

and then either post it here, or send it to support@rebex.net.
...