0 votes
by (140 points)

Hi Team,

We are using the Rebex FTP components (4.0.6755.0) in our .Net application. To download the files from the FTP, we are using the GetDownloadStream() method from Ftp() class. The method is working fine to download the stream. But after executing the method, if we call Disconnect() method, we are getting the Another operation is pending error message. We are having the C# code as follows.

Ftp client = new Ftp();
client.Connect(ftpSettings.ServerName, ftpSettings.PortNumber);
client.Login(ftpSettings.UserName, ftpSettings.Password);
byte[] fileData;
using (Stream responseStream = client.GetDownloadStream(ftpFilePath))
                {
                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        byte[] buffer = new byte[1024];
                        int bytesRead;
                        do
                        {
                            bytesRead = responseStream.Read(buffer, 0, buffer.Length);
                            memoryStream.Write(buffer, 0, bytesRead);
                        } while (bytesRead > 0);

                        fileData = memoryStream.ToArray();

                    }
                }

client.Disconnect();

This is very critical for us to fix the issue and release it to production. This is a showstopper issue in the production. Please help us to fix it. We look forward to your reply. Thank you.

Applies to: Rebex FTP/SSL

1 Answer

0 votes
by (148k points)

Hi,

When GetDownloadStream method has been called, most methods on that Ftp instance will fail with "Another operation is pending" error. FTP is a single-operation protocol, and until the stream has been closed, no other FTP operations are allowed, and that includes the QUIT command (represented by the Disconnect method).

For example, the following code would fail:

Ftp client = new Ftp();
client.Connect("test.rebex.net", 21);
client.Login("demo", "password");
var stream = client.GetDownloadStream("/pub/example/WinFormClient.png");
client.Disconnect();

In your sample code above, you do actually close the responseStream (via using block), so Disconnect should work as well. It would be a bug if it failed despite the stream having been closed.

However, we have not been able to reproduce the bug - if we change your code to download a file from one of our servers, it works fine.

Are you able to reproduce the issue using your code with test.rebex.net server (see the code snippet above) and /pub/example/WinFormClient.png file?

Also, please enable logging to see what is actually going on when the error occurs. To create a debug log, just add the following line to your code:

client.LogWriter = new Rebex.FileLogWriter("ftplog.txt", Rebex.LogLevel.Debug);

If needed, please post the content of ftplog.txt here or mail it to support@rebex.net for analysis.

...