0 votes
by (290 points)

I am connecting to the FTP server using FileTransferClient. It connects and logs in perfectly. But if I disconnect the connection and try connect again using same FileTransferClient object, I get InvalidOperationException. Message says client is already connected.

System.InvalidOperationException: Client is already connected.
   at Rebex.Net.FileTransferClient.fmlo()
   at Rebex.Net.FileTransferClient.ConnectAsync(String serverName, Int32 serverPort, FileTransferMode transferMode, Object state)

Rebex log:

2019-05-21 16:55:46.991 INFO FileTransferClient(1)[3] Response: 220-FileZilla Server 0.9.60 beta
2019-05-21 16:55:46.993 INFO FileTransferClient(1)[3] Response: 220-written by Tim Kosse (tim.kosse@filezilla-project.org)
2019-05-21 16:55:46.993 INFO FileTransferClient(1)[3] Response: 220 Please visit https://filezilla-project.org/
2019-05-21 16:55:47.050 INFO FileTransferClient(1)[3] Command: USER admin
2019-05-21 16:55:47.051 INFO FileTransferClient(1)[3] Response: 331 Password required for admin
2019-05-21 16:55:47.055 INFO FileTransferClient(1)[3] Command: PASS **********
2019-05-21 16:55:47.055 INFO FileTransferClient(1)[3] Response: 230 Logged on
2019-05-21 16:55:47.058 INFO FileTransferClient(1)[3] Command: FEAT
2019-05-21 16:55:47.058 INFO FileTransferClient(1)[3] Response: 211-Features:
2019-05-21 16:55:47.058 INFO FileTransferClient(1)[3] Response:  MDTM
2019-05-21 16:55:47.058 INFO FileTransferClient(1)[3] Response:  REST STREAM
2019-05-21 16:55:47.058 INFO FileTransferClient(1)[3] Response:  SIZE
2019-05-21 16:55:47.059 INFO FileTransferClient(1)[3] Response:  MLST type*;size*;modify*;
2019-05-21 16:55:47.059 INFO FileTransferClient(1)[3] Response:  MLSD
2019-05-21 16:55:47.059 INFO FileTransferClient(1)[3] Response:  UTF8
2019-05-21 16:55:47.059 INFO FileTransferClient(1)[3] Response:  CLNT
2019-05-21 16:55:47.059 INFO FileTransferClient(1)[3] Response:  MFMT
2019-05-21 16:55:47.059 INFO FileTransferClient(1)[3] Response:  EPSV
2019-05-21 16:55:47.059 INFO FileTransferClient(1)[3] Response:  EPRT
2019-05-21 16:55:47.059 INFO FileTransferClient(1)[3] Response: 211 End
2019-05-21 16:55:47.072 INFO FileTransferClient(1)[3] Command: SYST
2019-05-21 16:55:47.072 INFO FileTransferClient(1)[3] Response: 215 UNIX emulated by FileZilla
2019-05-21 16:55:47.073 INFO FileTransferClient(1)[3] Command: OPTS UTF8 ON
2019-05-21 16:55:47.073 INFO FileTransferClient(1)[3] Response: 202 UTF8 mode is always enabled. No need to send this command.
2019-05-21 16:55:47.081 INFO FileTransferClient(1)[7] Command: QUIT
2019-05-21 16:55:47.081 INFO FileTransferClient(1)[7] Response: 221 Goodbye
Applies to: Rebex FTP/SSL
by (73.5k points)
Which version of component you are using? The version should be included at the beginning of the log file.

I have just tried the same using the latest version, and it is working fine. I used this code:

            var client = new FileTransferClient();
            client.LogWriter = new ConsoleLogWriter(LogLevel.Info);

            client.Connect("test.rebex.net", FileTransferMode.Ftp);
            client.Login("demo","password");
            client.Disconnect();

            Console.WriteLine();

            client.Connect("test.rebex.net", FileTransferMode.Ftp);
            client.Login("demo", "password");
            client.Disconnect();

Is this working for you as well?
by (290 points)
edited by
I am using below code to connect and disconnect.

                var a = new FileTransferClient();
                a.LogWriter = new Rebex.FileLogWriter(@"C:\logs\ftplog.txt");
                a.FtpPassiveMode = true;
                await a.ConnectAsync("localhost", 21, FileTransferMode.Ftp);
                await a.LoginAsync("admin", "****");

                await a.DisconnectAsync();
                //a.Disconnect();

                await a.ConnectAsync("localhost", 21, FileTransferMode.Ftp);
                await a.LoginAsync("root", "****");

I verified and found that it's problem with DisconnectAsync(). If I use Disconnect it works fine without any error.

Why is it so and how can I work around this?
by (73.5k points)
Thank you for pointing to this.  There is a bug in the DisconnectAsync method, which causes the inner state is not reset to disconnected.

We will fix this in the next release. In the meantime you can workaround by:
1. Either create new instance for the new connection.
2. Or use synchronous Disconnect() method instead.
by (290 points)
Thanks for suggesting workarounds.

How can I subscribe for e-mails that whenever new version is released and this issue is fixed I am notified.
by (148k points)
You can subscribe to our newsletter at the following URL:
https://rebex.us5.list-manage.com/subscribe?u=6e0e34c882602d1cf12bc584b&id=e7c9ad3959

1 Answer

0 votes
by (148k points)

This issue was fixed in Rebex File Transfer Pack 2019 R3.

...