Archived Forum Post

Index of archived forum posts


Exception Handling in FTP

Oct 12 '12 at 00:59

While the Chilkat FTP2 documentation (under DebugLogFilePath) suggests crashes are rare, they do happen. I have been having a problem with an FTP server closing the connection in the middle of transferring 16,000 files. When this happens, FTP2 pops up a message box with a lot of useful details.

But when the box pops up, it stops all processing until it is closed manually. I want to be able to use a try-catch block to trap the exception. Something like:

bool success; try { success = ftp.PutFile(localFile, remoteFile); } catch (Exception ex) { // Log ex.Message and exit }

but the catch block is never executed.

Is there some way to (1) trap the exception that occurs when "socket is not ready for writing" is reported, (2) turn off the pop-up messages, or (3) simply have FTP2 return false?


1) The Chilkat methods never raise exceptions. The reason is that the Chilkat API is offered across many different programming languages, and in many cases there is no support for "try" ... "catch" exception handling. If a Chilkat method fails, it is indicated by a return value of False / 0 / Null, etc.

2) The Chilkat API's never pop-up messages. If a pop-up is happening, it is your own application code that is displaying the pop-up, not Chilkat.

3) As I mentioned in #1, a method indicates failure via the return value. For the PutFile method, it will return false to indicate failure.