0 votes
by (230 points)
edited

Hi,

i'm trying to send bulk of commands to my client (without considering if it's connected nor busy). since there is no event for IsBusy i can't really determine if client can accept my commands.

for example when i'm running:

var task = ftpHandler.Ftp.ChangeDirectoryAsync(dir);

task.ContinueWith(task1 =>
    {
        var listTask = ftpHandler.Ftp.GetListAsync();

        listTask.ContinueWith(task2 =>
            {
                var list = task2.Result;

                foreach (var listItem in list)
                {
                    LoggerRepository.AddMessage(listItem.Name);
                }
            });
    });

i get "Another operation is pending". is there a way to determine if the client is ready to execute commands ?

Applies to: Rebex FTP/SSL

1 Answer

+1 vote
by (73.6k points)
edited

This error is raised when you are trying to execute two methods simultaneously on the Ftp object. Because the code you provided is logically correct, I suppose that the cause of the problem is somewhere else.

Please note, that you cannot use Ftp object until the specified code is completed. This leads to design like this:

var ftp = new Ftp();
ftp.Connect(...);
ftp.Login(...);

var task = ftp.ChangeDirectoryAsync("/");

task = task.ContinueWith(task1 =>
{
    // simply call synchronous methods, 
    // because continuation task is run asynchronously
    var list = ftp.GetList();
    foreach (var listItem in list)
    {
        LoggerRepository.AddMessage(listItem.Name);
    }
});

task.Wait();

// now you can use Ftp object again 
// ...
ftp.ChangeDirectoryAsync("/home");
...
...