Hi, I'm writing a simple program that are downloading several files at the same time in different threads and It seems that as soon as the first file is finished all other file downloads ends with this exception: error in thread = 4 filename = movie1.wmv, error = An existing connection was forcibly closed by the remote host System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host.

It works fine before the first file is ready and I have five files downloading at same time.

Anyone have an idea what the problem can be? the server being used is Titan.

The code looks like this when starting the download for every file.

try
{
    Ftp client = new Ftp();
    client.Connect(hostname, port);
    client.Login(username, password);
    long fileSize = client.GetFile(fileName, fileNameWithPath);
}
catch (Exception ex)
{
    ...
}

asked 16 Mar '10, 13:57

Martin's gravatar image

Martin
162
accept rate: 0%

edited 16 Mar '10, 15:00


Hi,

the FTP protocol does not support multiple file transfers in the same time.

If you want to download several files at once you have to maintaint multiple connections to the FTP server. This can cause problems with some FTP servers because they like to limit number of concurent connections from one user or from one IP address. The most common limit is 2 concurent transfers per user.

Pseudo code for downloading the file in two threads would look like this:

FileNameBuffer buffer = GetFileListFromFtpServer();
StartFirstDownloadThread(files);
StartSecondDownloadThread(files);

Pseudo code for each download thread would be:

ConnectToFtp();
while (file = GetNextFileFromBuffer())
{
   DownloadFile();
}
Disconnect();

You can download the fully functional code for downloading all files from FTP folder in two threads from http://www.rebex.net/extras/FtpsMultiDownloader.zip

If you want to include a support for simulataneous transfers directly to the FTP component please consider voting on the following feature requests:

link

answered 16 Mar '10, 16:41

Martin%20Vobr's gravatar image

Martin Vobr ♦♦
335310
accept rate: 37%

Hi and thanks for your answer. The thing is that I do it like in your example and it works sometimes. It can start up five downloads at the same time and they download without any problems.

The problem is that sometimes(and usually when the first file is fully downloaded) the rest of the files disconnects as well(and the strange thing is that it doesn't happen all the times?).

Downloading against same ftp server with filezilla works fine without a problem.

(18 Mar '10, 08:05) Martin

Hi,

following answer from Lukas could help:

http://forum.rebex.net/questions/112/multiple-downloads-continue-from-earlier-thread/113#113

(18 Mar '10, 17:54) Martin Vobr ♦♦
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×136
×19
×9

Asked: 16 Mar '10, 13:57

Seen: 895 times

Last updated: 30 Mar '11, 08:22