0 votes

I have small utility we are building for uploading very large files to FTP server (many GBs). We are using VB.NET.

I anticipate occasional network errors considering the uploads will run over many hours.

We have our upload method inside a try/catch block, however there are other numerous calls on the ftp client throughout the utility.

I'd like to have a simple technique for handling a failed connection that recreates / reconnects / retries the current operation. Wrapping every call to ftpclient with try/catch is tedious and error prone.

Is there a retry feature in FTP-DLL, And/Or can you provide a recommended pattern that we can implement to handle this scenario? Basically, a wait x-time between retries, retry n times

I'm also wondering if there is an overall error event fired by FTP-dll that we could handle to allow for a reconnect / retry

by

1 Answer

0 votes

There is no auto-retry feature in Ftp.dll. There is no way to create a 'simple' retry mechanism, if your code is complicated. I mean - if you perform complex tasks you need to record what has been done already, and what needs to be performed in future.

There are two Upload method overloads, you can use to start uploading at specified remote file position (Your server must support REST command in such case)

FtpResponse Upload(string remotePath, long remoteStartPosition, Stream source)
FtpResponse Upload(string remotePath, long remoteStartPosition, byte[] data)

You can ether record the number of bytes already transferred using Progress event or better getting the file size, just before you retry the upload.

All errors are reported as standard .NET exceptions. FtpResponse exception means the server returned an error - it means that you don't need to reconnect. All other exceptions may mean there was a communication problem and you need to reconnect.

by (301k points)
...