How to handle FTP connectivity lost

Hello All,
I have to retrieve Flat files from FTP server. I have been asked to handle the situation for FTP connectivity lost during transfer. While retrieving a large file, if FTP connection is lost, I am getting the incomplete file in local directory and that service(pub.client:ftp) is not completing and not even throwing any error.
How to handle this situation bcoz i need to send some notification in such connectivity lost.
I am sure many of you have already handled this situation…
Waiting for a solution…


If you use filepolling mechanism in IS6.x it helps for troubleshooting for lost or incomplete processing files which will put in Error directory that you specified.

But if you want to catch the error like connection timeout or socket closed using ftp file transfer,in this case you need to implement try/catch blocks catch the ftp exception and alert the team regarding failure of file transfer.


I tried to implement Try-Catch block as you suggested but for a connectivity lost that service is not getting completed and not even throwing any exception so its very difficult to handle it in catch block.
Is file polling is only way for handling this issue.?
Please suggest some way to handle that connection timeout or connectivity lost issue.
One more thing, is there any way to stop execution of a service if its in never ending situation.
Waiting for your response…

FTP client is not going to jump to the catch block on error. If you look at the output of the service you will see returncode, returnmsg etc. These will contain the ftp error msg such as connection failed. You must then throw the error based upon the content of the msg. WmDB works pretty much the same way. The error is being returned in a msg. If you are using the broker to initiate the service then you can throw a runtime exception based upon the content and it will automatically retry for you.


I will get returncode,returnmsg only when that service completes execution. While trasfering a large file, if FTP connection is lost in between, the service is not completing execution so i am not able to get any returncode or returnmsg as suggested by you.Its in never ending situation…
Please help me to get some solution as it is very urgent!

FTP is not a reliable protocol so you are going to have to get creative to make it behave that way. You have several options. You should separate out you connect statement and evaluate the output, same as if you were using WmDB. If you can’t connect then you can retry if broker supplied. If not you can still retry using a repeat.

For timeouts, there are multiple solutions. You can launch a background thread and use sync and notify. There are examples of this in the WmSamples package. The only issue with this is you don’t know how to wait especially for large files. So you might want to code some flow logic to determine if the file was downloaded successfully. ie Once the timeout has expired and you don’t receive a returncode or returnmessage, then you can assume your ftp timed out and you need to try again. You should also set your to something reasonable otherwise you might hang for a while.