• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 8762
  • Last Modified:

C# - how to ftp multiple files on a single connection with FtpWebRequest object

hello all.
  i am having trouble trying to upload multiple files on a single connection with the ftpWebRequest object in C#.

basically i can get it to upload a single file, but when it comes back to the top of the loop and i try to say
Stream requestStream = myFTP.GetRequestStream()

i get an error saying:
   "Cannot re-call BeginGetRequestStream/BeginGetResponse while a previous call is still in progress."

and i already see that the previous upload ended with this response:
ClosingData - 226 Transfer OK

i wrap the requestStream declaration in a using statement as well as the .GetResponse() call
like this:
using (FtpWebResponse response = (FtpWebResponse)l_oFTP.GetResponse())
   //print out the status code and it says ClosingData - 226 Transfer OK

any ideas?

thanks in advance.
2 Solutions
Take a look at the response from Lushdog in this post:

He claims that only a single connection is used.

It is because of you are using Stream requestStream, you need to use requestStream for every file and need to close it requestStream.Close() after every upload.

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now