0 votes
by (170 points)

Hello,

I'm trying to use the Rebex FTP/SSL library.

I'm connected successfully to a Java server.

But i can't do anything with the client (Upload / Download / Rename / Delete).

When i'm trying i have this error message :

Rebex.Net.FtpException: Timeout exceeded.
at Rebex.Net.Ftp.TL () [0x000a4] in <6ec8d5f3f62a4b8bb1098f4ae2b7edbe>:0
at Rebex.Net.Ftp.RL (System.Int32 Z, System.Boolean T) [0x000ea] in <6ec8d5f3f62a4b8bb1098f4ae2b7edbe>:0

Here is the code :

try
        {
            client.Rename("/Hello.txt", "/file.txt");
        }
        catch (Exception e)
        {
            Debug.WriteLine("FTPDebug : err " + e.ToString());
        }

I've seen this post on the forum : http://forum.rebex.net/3857/smtp-timeout-exception-when-trying-to-send?show=3857#q3857

The solution was to disable the Chunking and Pipelining extensions.

But it was for VB and i'm programming with Xamarin.

Chuking and Pipelining are only for SMTP ?
How can i disable them ?
Btw i'm using Visual Studio 2015 community and Xamarin 4.4.0.34

Thanks for reading me !

Applies to: Rebex FTP/SSL

1 Answer

0 votes
by (73.5k points)

Hello,

the mentioned answer was for SMTP protocol only. FTP protocol has other specialties, which can be utilized.

Can you please send us communication log to support@rebex.net, it can expose the source of the problem (session settings, etc.)
The log can be created like this:

var client = new Rebex.Net.Ftp();
client.LogWriter = new Rebex.FileLogWriter(@"c:\data\ftp.log", Rebex.LogLevel.Debug);
by (170 points)
Heya ! I've send an email to the Rebex support with the log file.

If someone is interessted (maybe other users) here is the log :

2017-04-21 10:19:22.229 DEBUG Ftp(1)[10] Info: Establishing data connection to 192.168.43.125:44261.
2017-04-21 10:19:22.240 DEBUG Ftp(1)[10] Info: Established data connection from 192.168.43.1:51435.
2017-04-21 10:19:22.242 INFO Ftp(1)[10] Command: MLSD
2017-04-21 10:19:22.248 INFO Ftp(1)[10] Response: 150 File status okay; about to open data connection.
2017-04-21 10:19:22.250 DEBUG Ftp(1)[10] Info: Upgrading data connection to TLS/SSL.
2017-04-21 10:19:22.254 DEBUG Ftp(1)[10] TLS: Data connection: Asking the server to resume session ID:
 0000 |9A-72-E3-59-3A-E3-C5-F6 92-7A-0D-D4-49-8A-94-83| .r.Y:....z..I...
 0010 |CD-83-0F-15-63-6D-97-23 CA-97-9A-A9-B1-72-6B-60| ....cm.#.....rk`
2017-04-21 10:19:22.254 INFO Ftp(1)[10] TLS: Data connection: State StateChange:Negotiating
2017-04-21 10:19:22.254 DEBUG Ftp(1)[10] TLS: Data connection: HandshakeMessage:ClientHello was sent.
2017-04-21 10:19:24.198 DEBUG Ftp(1)[10] TLS: Data connection: HandshakeMessage:ServerHello was received.
2017-04-21 10:19:24.200 INFO Ftp(1)[10] TLS: Data connection: Using TLS 1.2.
2017-04-21 10:19:24.201 DEBUG Ftp(1)[10] TLS: Data connection: The server supports secure renegotiation.
2017-04-21 10:19:24.204 DEBUG Ftp(1)[10] TLS: Data connection: HandshakeMessage:Certificate was received.
2017-04-21 10:19:24.206 DEBUG Ftp(1)[10] TLS: Data connection: HandshakeMessage:ServerKeyExchange was received.
2017-04-21 10:19:24.207 DEBUG Ftp(1)[10] TLS: Data connection: HandshakeMessage:ServerHelloDone was received.
2017-04-21 10:19:24.209 DEBUG Ftp(1)[10] TLS: Data connection: Verifying server certificate ('CN=localhost').
2017-04-21 10:19:24.209 DEBUG Ftp(1)[10] TLS: Data connection: Certificate verification result: Accept
2017-04-21 10:19:24.220 DEBUG Ftp(1)[10] TLS: Data connection: Received ephemeral Diffie-Hellman prime.
2017-04-21 10:19:24.249 DEBUG Ftp(1)[10] TLS: Data connection: Ephemeral Diffie-Hellman prime size is 1024 bits (minimum allowed size is 1024 bits).
2017-04-21 10:19:24.275 DEBUG Ftp(1)[10] TLS: Data connection: HandshakeMessage:ClientKeyExchange was sent.
2017-04-21 10:19:24.278 DEBUG Ftp(1)[10] TLS: Data connection: CipherSpec:ChangeCipherSpec was sent.
2017-04-21 10:19:24.279 DEBUG Ftp(1)[10] TLS: Data connection: HandshakeMessage:Finished was sent.
2017-04-21 10:19:24.291 DEBUG Ftp(1)[10] TLS: Data connection: CipherSpec:ChangeCipherSpec was received.
2017-04-21 10:19:24.292 DEBUG Ftp(1)[10] TLS: Data connection: HandshakeMessage:Finished was received.
2017-04-21 10:19:24.293 INFO Ftp(1)[10] TLS: Data connection: State StateChange:Secured
2017-04-21 10:19:24.294 INFO Ftp(1)[10] TLS: Data connection: Connection secured using cipher: TLS 1.2, RSA with ephemeral Diffie-Hellman, 128bit AES in CBC mode, SHA1
2017-04-21 10:19:24.294 DEBUG Ftp(1)[10] TLS: Data connection: Session ID:
 0000 |1C-7F-F1-51-51-E9-42-55 A7-9A-71-8B-67-8B-28-8D| ...QQ.BU..q.g.(.
 0010 |84-4A-5B-59-5A-B0-3D-3D 9D-0A-00-5C-E9-4A-B5-96| .J[YZ.==...\.J..
2017-04-21 10:19:24.294 DEBUG Ftp(1)[10] Info: Data connection upgraded to TLS/SSL.
2017-04-21 10:19:24.315 INFO Ftp(1)[10] Response: 226 Closing data connection.
2017-04-21 10:19:24.326 DEBUG Ftp(1)[10] Info: Item: Size=32768;Modify=20170420113702.000;Type=dir;Perm=elfpcm; Directory
2017-04-21 10:19:24.374 DEBUG Ftp(1)[10] Info: Item: Size=7;Modify=20170420023656.000;Type=file;Perm=radfw; Hello.txt
2017-04-21 10:19:24.376 DEBUG Ftp(1)[10] Info: Item: Size=0;Modify=20170420092548.000;Type=file;Perm=radfw; Helow.txt
2017-04-21 10:19:24.377 DEBUG Ftp(1)[10] Info: Item: Size=2032;Modify=20170420133416.000;Type=file;Perm=radfw; keyStore.bks
2017-04-21 10:19:24.386 INFO Ftp(1)[10] TLS: Data connection: Alert Alert:Alert was received.
2017-04-21 10:19:24.391 INFO Ftp(1)[10] TLS: Data connection: Alert Alert:Alert was sent.
2017-04-21 10:19:24.392 INFO Ftp(1)[10] TLS: Data connection: State StateChange:Closed
2017-04-21 10:19:24.410 DEBUG Ftp(1)[10] Info: Data transfer ended. 272 bytes transferred.
2017-04-21 10:19:24.414 DEBUG Ftp(1)[10] Info: Closing downloading data connection.
2017-04-21 10:19:24.417 DEBUG Ftp(1)[10] TLS: Data connection: Closing TLS socket.
2017-04-21 10:19:24.421 DEBUG Ftp(1)[10] Info: Transfer ended successfully.
2017-04-21 10:19:24.423 DEBUG Ftp(1)[10] Info: Data connection closed.
2017-04-21 10:19:24.441 DEBUG Ftp(1)[10] Info: Starting data transfer.
2017-04-21 10:19:24.442 INFO Ftp(1)[10] Command: PASV
2017-04-21 10:19:24.459 INFO Ftp(1)[10] Response: 227 Entering Passive Mode (192,168,43,125,229,139)
2017-04-21 10:19:24.459 DEBUG Ftp(1)[10] Info: Establishing data connection to 192.168.43.125:58763.
2017-04-21 10:19:24.478 DEBUG Ftp(1)[10] Info: Established data connection from 192.168.43.1:35894.
2017-04-21 10:19:24.482 INFO Ftp(1)[10] Command: NLST /DIrectory/
2017-04-21 10:20:24.973 INFO Ftp(1)[10] Info: Timing out.
2017-04-21 10:20:25.030 DEBUG Ftp(1)[10] Info: Error while starting data transfer: Rebex.Net.FtpException: Timeout exceeded.
  at Rebex.Net.Ftp.TL () [0x000a4] in <6ec8d5f3f62a4b8bb1098f4ae2b7edbe>:0
  at Rebex.Net.Ftp.RL (System.Int32 Z, System.Boolean T) [0x000ea] in <6ec8d5f3f62a4b8bb1098f4ae2b7edbe>:0
2017-04-21 10:20:25.031 DEBUG Ftp(1)[10] Info: Error while initializing data connection.
2017-04-21 10:20:25.035 ERROR Ftp(1)[10] Info: Rebex.Net.FtpException: Timeout exceeded.
  at Rebex.Net.Ftp.TL () [0x000a4] in <6ec8d5f3f62a4b8bb1098f4ae2b7edbe>:0
  at Rebex.Net.Ftp.RL (System.Int32 Z, System.Boolean T) [0x000ea] in <6ec8d5f3f62a4b8bb1098f4ae2b7edbe>:0
2017-04-21 10:20:25.037 ERROR Ftp(1)[10] Info: Rebex.Net.FtpException: Timeout exceeded.
  at Rebex.Net.Ftp.TL () [0x000a4] in <6ec8d5f3f62a4b8bb1098f4ae2b7edbe>:0
  at Rebex.Net.Ftp.RL (System.Int32 Z, System.Boolean T) [0x000ea] in <6ec8d5f3f62a4b8bb1098f4ae2b7edbe>:0
by (170 points)
I've maybe find something.

I found MaxDownloadSpeed and MaxUploadSpeet boolean.

They are both at 0.

Is this normal ?
by (170 points)
These modifications

            client.MaxDownloadSpeed = 4 * 1024;
            client.MaxUploadSpeed = 2 * 1024;

doesn't change anything
by (73.5k points)
Yes, it is normal. Zero means unlimited speed.

I have sent you response to your email recently. Have you tried my suggestions? I will write the result here, when we find the solution.
by (170 points)
Heya !

Yeah i've tried your solution but it doesn't work.

Sorry for the bad log, i tried so many things and i forget some changes.

I've tried with the GetList fonction and Rename fonction (example i've wrote before) and still Timeout Exceeded.
by (73.5k points)
So, can you please send us log produced by this code:

    var client = new Rebex.Net.Ftp();
    client.LogWriter = new Rebex.FileLogWriter(@"c:\data\ftp.log", Rebex.LogLevel.Debug);
    client.Connect(hostname);
    client.Login(username, password);
    client.Rename("Hello.txt", "file.txt");
by (170 points)
Yep i'll do this right now
by (170 points)
Hello again !

It works now !

I just try the Rename focntion, i'll try the GetFile right now (Btw, why this "/" failed ? )
by (73.5k points)
Great. So it seems your server doesn't support absolute paths. You always have to use the relative ones.

To navigate down the directory hierarchy, use the client.ChangeDirectory("dir") method.
To navigate up, use two dots like this client.ChangeDirectory("..").

Why your server fails with "/" is question to your server vendor. Some servers just don't support it and you can work in current directory only.
by (170 points)
Okay, but i've tried to download a file like this :

client.GetFile("Tamer.txt", "storage/emulated/0/TestDirectory/test.txt");

Should i delete all "/" even if they aren't on the server ?
by (73.5k points)
No, for local paths don't remove slashes. Only the remote paths makes problems.
by (170 points)
Okay thanks !

Btw i've still a timeout whith this line

client.GetFile("Tamer.txt", "storage/emulated/0/TestDirectory/test.txt");

(I've sended the log file at support)
by (73.5k points)
I am just looking at it. I will send you reply ASAP.
by (170 points)
Okay !

Thanks again for the help guy !
by (170 points)
Okay !

Thanks to lukas i've a new error right now !

I add these following lines :

client.Settings.KeepAliveDuringTransfer = true;
              client.Settings.KeepAliveDuringTransferInterval = 30;

and

client.ClearCommandChannel();

after client.Connect.

2017-04-21 16:57:48.422 INFO Ftp(1)[9] Response: 220 Service ready for new user.
2017-04-21 16:57:48.438 INFO Ftp(1)[9] Command: PBSZ 0
2017-04-21 16:57:48.566 INFO Ftp(1)[9] Response: 200 Command PBSZ okay.
2017-04-21 16:57:48.566 INFO Ftp(1)[9] Command: PROT P
2017-04-21 16:57:48.571 INFO Ftp(1)[9] Response: 200 Command PROT okay.
2017-04-21 16:57:48.572 INFO Ftp(1)[9] Command: CCC
2017-04-21 16:57:48.577 INFO Ftp(1)[9] Response: 530 Access denied.
2017-04-21 16:57:48.626 ERROR Ftp(1)[9] Info: System.ArgumentException: Argument passed in is not serializable.
Parameter name: value
  at System.Collections.ListDictionaryInternal.set_Item (System.Object key, System.Object value) [0x00056] in /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/referencesource/mscorlib/system/collections/listdictionaryinternal.cs:61
  at Rebex.Net.FtpException.NE (Rebex.Net.FtpResponse Z) [0x00031] in <6ec8d5f3f62a4b8bb1098f4ae2b7edbe>:0
  at Rebex.Net.FtpException..ctor (Rebex.Net.FtpResponse Z, System.Exception T) [0x0006e] in <6ec8d5f3f62a4b8bb1098f4ae2b7edbe>:0
  at Rebex.Net.FtpException..ctor (Rebex.Net.FtpResponse response) [0x00000] in <6ec8d5f3f62a4b8bb1098f4ae2b7edbe>:0
  at Rebex.Net.Ftp.RL (System.Int32 Z, System.Boolean T) [0x000e3] in <6ec8d5f3f62a4b8bb1098f4ae2b7edbe>:0
  at Rebex.Net.Ftp.RL (System.Int32 Z) [0x00000] in <6ec8d5f3f62a4b8bb1098f4ae2b7edbe>:0
  at Rebex.Net.Ftp.OU () [0x000b4] in <6ec8d5f3f62a4b8bb1098f4ae2b7edbe>:0

I'm pretty sure the problem come from my Phone. But, how can i now wich param is denied ?

Thanks again for the amazing help !
by (148k points)
The real issue in this case is the "530 Access denied" error reported by the FTP server, suggesting that the server doesn't support the "Clear Command Channel" feature (Rebex Ftp.ClearCommandChannel method). To solve that, either enable the feature at the server, or don't use the CCC command.

The misleading "Argument passed in is not serializable" error is a known Rebex FTP/SSL issue with latest Xamarin.Android releases caused by a breaking change in Xamarin.Android and Mono. This occurs when an attempt is made to throw another exception. We have fixed this in version 2017 R3: http://www.rebex.net/total-pack/history.aspx#2017R3
by (170 points)
edited by
Hello,

Thanks again for the help, i've sended the new log file to the support.

Still the same problem. I can't Download, 'cause of Timeout

Info: Starting data transfer.
2017-04-24 11:05:53.901 INFO Ftp(1)[7] Command: TYPE I
2017-04-24 11:05:54.117 INFO Ftp(1)[7] Response: 200 Command TYPE okay.
2017-04-24 11:05:54.123 INFO Ftp(1)[7] Command: PASV
2017-04-24 11:05:54.286 INFO Ftp(1)[7] Response: 227 Entering Passive Mode (192,168,43,235,162,113)
2017-04-24 11:05:54.290 DEBUG Ftp(1)[7] Info: Establishing data connection to 192.168.43.235:41585.
2017-04-24 11:05:54.301 DEBUG Ftp(1)[7] Info: Established data connection from 192.168.43.1:42377.
2017-04-24 11:05:54.305 INFO Ftp(1)[7] Command: RETR Tamer.txt
2017-04-24 11:06:54.469 INFO Ftp(1)[7] Info: Timing out.
2017-04-24 11:06:54.487 DEBUG Ftp(1)[7] Info: Error while starting data transfer: Rebex.Net.FtpException: Timeout exceeded.
  at Rebex.Net.Ftp.TL () [0x000a4] in <6ec8d5f3f62a4b8bb1098f4ae2b7edbe>:0
  at Rebex.Net.Ftp.RL (System.Int32 Z, System.Boolean T) [0x000ea] in <6ec8d5f3f62a4b8bb1098f4ae2b7edbe>:0
2017-04-24 11:06:54.492 DEBUG Ftp(1)[7] Info: Error while initializing data connection.
2017-04-24 11:06:54.510 ERROR Ftp(1)[7] Info: Rebex.Net.FtpException: Timeout exceeded.
  at Rebex.Net.Ftp.TL () [0x000a4] in <6ec8d5f3f62a4b8bb1098f4ae2b7edbe>:0
  at Rebex.Net.Ftp.RL (System.Int32 Z, System.Boolean T) [0x000ea] in <6ec8d5f3f62a4b8bb1098f4ae2b7edbe>:0
2017-04-24 11:06:54.523 ERROR Ftp(1)[7] Info: Rebex.Net.FtpException: Timeout exceeded.
  at Rebex.Net.Ftp.TL () [0x000a4] in <6ec8d5f3f62a4b8bb1098f4ae2b7edbe>:0
  at Rebex.Net.Ftp.RL (System.Int32 Z, System.Boolean T) [0x000ea] in <6ec8d5f3f62a4b8bb1098f4ae2b7edbe>:0
2017-04-24 11:06:58.984 DEBUG Ftp(1)[13] TLS: Closing TLS socket.
2017-04-24 11:06:58.985 INFO Ftp(1)[13] TLS: Alert Alert:Alert was sent.
2017-04-24 11:06:58.985 INFO Ftp(1)[13] TLS: State StateChange:Closed

Now the rename function return me a 553 reponses :

Response: 211 End
2017-04-24 11:44:41.528 INFO Ftp(1)[9] Command: OPTS UTF8 ON
2017-04-24 11:44:41.533 INFO Ftp(1)[9] Response: 200 Command OPTS okay.
2017-04-24 11:44:41.541 INFO Ftp(1)[9] Command: OPTS MLST Size;Modify;Type;Perm;
2017-04-24 11:44:41.635 INFO Ftp(1)[9] Response: 200 Command OPTS okay.
2017-04-24 11:44:41.642 INFO Ftp(1)[9] Command: RNFR Tamer.txt
2017-04-24 11:44:41.647 INFO Ftp(1)[9] Response: 350 Requested file action pending further information.
2017-04-24 11:44:41.647 INFO Ftp(1)[9] Command: RNTO file.txt
2017-04-24 11:44:41.661 INFO Ftp(1)[9] Response: 553 Can't rename file.
2017-04-24 11:44:41.749 ERROR Ftp(1)[9] Info: System.ArgumentException: Argument passed in is not serializable.

I've seen that the 553 error could be an invalid permission. So how can i check the user's right ?

Edit :Okay i found that 553 error could be a "file lready exists" That's why it crashed. Now it's working
by (73.5k points)
The reason why you cannot rename the file should be described by the server, but your server didn't do that.

Basically, it can mean that you are trying to rename nonexisting file, or you are trying to rename file to another already existing file, or you don't have permission to rename the file, or the file is locked.

Unfortunately, there is no general way to determine file permissions.
However, some servers send this information to the client when listing directories.
So you can try to call Ftp.GetList() or  Ftp.GetList("file.txt") and then check the `Permissions` property of returned `FtpItem` objects.

If the server supports it, a response can look like this:
  -rw-r--r--  1 tester tester  220 Apr 19  2015 readme.txt

If the server doesn't support it, a response looks like this:
  04-08-14  04:09PM                  403 readme.txt
by (170 points)
edited by
I've used the ls -l command with adb shell and i've all permission on /storage/sdcard0/

But when the client is connected, i've to use a couple of login / server (define on server properties). The server can give write permission to the user, but how can i check these rights from the client of Rebex ? (if i can ofc)

And i just read this on the log "Type=file;Perm=radfw; Tamer.txt" what "radfw" mean ?

Thanks again for the help
by (73.5k points)
The Perm values are defined in RFC3659 (https://tools.ietf.org/html/rfc3659#section-7.5.5)

The "radfw" mean: read, append, delete, rename, write.

Unfortunately, this type of permissions is not supported by the Rebex FTP.
by (170 points)
edited by
Hello !

New upgrade about the post !

I've used a tierce android FTP/SSL Server and the connection was perfect.

Then i'm thinking it's really about the FTP Server i made.

The server didn't support SSL so i have to add few functions to make it work.
I generate my own keystore in .BKS. Then i load it on the SslConfigurationFactory.
Finally i set the ImplicitSsl boolean to true.

If i set this bool, i can only connect myself with SslMode.Implicit. I can't connect with SslMode.None (seems logic)
If i set this bool at false, i can't connect myself with SslModeImplicit or Explicit (error 431 Service is unavailable for Explicit mode and Invalid TLS packet received for Implicit). I can only use None mode.

When the bool is at True and SslMode at Implicit, i can Rename files, but i can't GetFile or PutFile.

I've tried to catch the certificate by my own (without the SslAcceptAllCertificates) but, even if i have a EventHandler, i can't catch the Certificate Custom Validation.

client.ValidatingCertificate += ftp_ValidatingCertificate;

Can the certificate block the download function ?
When i tried with a tierce FTP/SSL server it works perfectly with SslMode.None. Is it because i do something wrong when i create my own certificate ?

Thanks again for helping me guys !
by (170 points)
Hello again !

After few research it's appear that the problem can come from client's passive mode.

Can i use active mode instead ?

EDIT: Found
by (148k points)
Active mode with TLS/SSL is notoriously firewall-unfriendly. Passive mode is usually a better choice.
by (170 points)
Hello !

Yeah, i've tried many things.

Actually, i've still the same error. I'm sure now it's coming from the server. Then you can't do anything for me, i'll up the solution when i'll find it.

By the way, thanks for the supports, i really appreciate the helps !
by (148k points)
If passive mode over TLS/SSL doesn't work due to a misconfigured FTP server which is unable to accept those data connections, it might still be possible to get the active mode working. From the server's point-of-view, active mode is simple. But it poses a big challenge for the client which needs to be able to accept incoming connections from the server - and that requires a specifically configured firewall at the client.

Yet another option worth considering would be switching to another protocol - SFTP runs over SSH which only uses a single connection (on port 22) for both data and commands, eliminating the firewall-related problems that have been plaguing the FTP protocol since early 1990s, when firewalls became widespread.
by (170 points)
Hello !

Thanks for the quick reply, i was thinking about an SFTP server instead of the FTP / SSL.

The server is made on a Android's hotspot and i can't find anything if there is some firewalls.
...