0 votes
by (120 points)


I need to create multiple copies of a file on the same FTPS server using ftp.PutFile(Stream sourceStream, string remotePath) method. However, when I run my application, every time I get Rebex.Net.FtpException as "Another operation is pending."
Here is my code.

using (var stream = ftp.GetDownloadStream(filePath))
  ftp.PutFile(stream, filePath1);
Applies to: Rebex FTP/SSL

1 Answer

0 votes
by (3.9k points)


the thing is that a single FTP server session can not do multiple operations simultaneously. Nevertheless you can establish two sessions for the same user to work around this limitation:

var ftp1 = new Rebex.Net.Ftp();
ftp1.Connect(hostname, port);
ftp1.Login(username, password);

var ftp2 = new Rebex.Net.Ftp();
ftp2.Connect(hostname, port);
ftp2.Login(username, password);

// make copy of file
using (var stream = ftp1.GetDownloadStream(filePath))
    ftp2.PutFile(stream, filePath1);

However, please be aware that file data is actually going to be downloaded by the client and uploaded again, which is inefficient. If the server has been configured to allow server-to-server transfers, the following approach would eliminate the round-trip:

// copy a single file to the destination server
ftp1.CopyToAnotherServer(ftp2, filePath, filePath1);