views:

341

answers:

3

Hello. I am writing a program in C# / VS2005 to back up our production database, compress it, and transfer it to a remote server. I have a simple ftp site set up on the remote server.

The problem is that the file only transfers about half way (~500 - 600 MB) and the program throws the exception:

"An existing connection was forcibly closed by the remote host"

The code I am using was basically cut and pasted from here, written by Jaimon Mathew, using sockets:

http://www.csharphelp.com/archives/archive9.html

I have researched the problem and it doesn't look like there is anything I can do to prevent the connection from being closed, and my only way to fix it is to use the 'asynchronous' methods of the sockets.

I have been searching and can not find any sample code to do this, and I can not believe that this simple task that I am trying to perform is proving so difficult.

Is there a simple way to transfer a large (~1.2 GB) local file to a remote ftp site, which will not fail if the connection is closed by the remote host (I am guessing it would have to re-connect and resume the transfer)?

My boss is going to kill me if he finds out how much time I have spent on this already, and we still don't have a backup from the previous day on the remote server.

I would prefer to do everything from within the .NET program (our system currently is a giant Rube Goldberg machine), but I need a quick and easy solution.

Thanks,

Steve

+1  A: 

The code you linked appears to support resuming uploads:

public void upload(string fileName,Boolean resume)

Does calling that function with resume = true not work?

Chad Birch
I am going to try and find out...
Steve
I guess I should feel dumb for not trying this sooner... I added some code to the upload method so that it would exit if the connection is closed, and had to change a few other things to get it to work. THANK YOU!!!
Steve
+2  A: 

Here's a whole bunch of C# examples of how to do FTP. In particular, have a look at the Restart/Retry FTP Upload example.

Ben S
Thanks for your response. I saw that too, but it looks like those code samples use a component that requires a license, and I was hoping to find something that I didn't need to buy a license for. I thought that this would be a trivial thing to do.
Steve
A: 

I'm using Background Intelligent Transfer Service (BITS), to upload over HTTP. It is a platform-specific solution, but works fine and is easy to use. It is the same mechanism used by Windows Update.

Jeroen Landheer