We help IT Professionals succeed at work.

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.
Watch Question

Top Expert 2007
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.