robinrodricks / FluentFTP

An FTP and FTPS client for .NET & .NET Standard, optimized for speed. Provides extensive FTP commands, File uploads/downloads, SSL/TLS connections, Automatic directory listing parsing, File hashing/checksums, File permissions/CHMOD, FTP proxies, FXP support, UTF-8 support, Async/await support, Powershell support and more. Written entirely in C#.
MIT License
3.1k stars 651 forks source link

No working data connection (proftpd) #675

Closed maftieu closed 3 years ago

maftieu commented 3 years ago

FTP OS: Unix

FTP Server: ProFTPD (in french)

Computer OS: Windows 10 Pro 20H2 (19042.4746)

FluentFTP Version: 33.0.3

Unable to open any PASV data connection. Works well with Filezilla from the same computer.

I don't know what I do wrong, and I don't really see differences in commands from FluentFTP or FileZilla...

Logs :

# ConnectAsync()
Status:   Connecting to ***:21
Response: 220 ProFTPD 1.3.5b Server (xxxx.xxxx.local)
Status:   Detected FTP server: ProFTPD
Command:  AUTH TLS
Response: 234 AUTH TLS ex??cut?? avec succ??s
Status:   FTPS Authentication Successful
Status:   Time to activate encryption: 0h 0m 0s.  Total Seconds: 0,0536699.
Command:  USER ***
Response: 331 Mot de passe requis pour ***
Command:  PASS ***
Response: 230 Utilisateur *** authentifi??
Command:  PBSZ 0
Response: 200 PBSZ 0 ex??cut?? avec succ??s
Command:  PROT P
Response: 200 Protection set to Private
Command:  FEAT
Response: 211-Features:
Response: SITE UTIME
Response: MDTM
Response: SITE RMDIR
Response: SSCN
Response: TVFS
Response: SITE COPY
Response: MFMT
Response: SIZE
Response: LANG fr-FR.UTF-8*;fr-FR
Response: PROT
Response: CCC
Response: SITE MKDIR
Response: PBSZ
Response: AUTH TLS
Response: MFF modify;UNIX.group;UNIX.mode;
Response: REST STREAM
Response: MLST modify*;perm*;size*;type*;unique*;UNIX.group*;UNIX.mode*;UNIX.owner*;
Response: UTF8
Response: EPRT
Response: SITE SYMLINK
Response: EPSV
Response: 211 Fin
Status:   Text encoding: System.Text.UTF8Encoding
Command:  OPTS UTF8 ON
Response: 200 UTF-8 activé
Command:  SYST
Response: 215 UNIX Type: L8
*** List files ***

# GetListing(null, Auto)

# GetWorkingDirectory()
Command:  PWD
Response: 257 "/" est le répertoire courant
Command:  TYPE I
Response: 200 Type paramétré à I

# OpenPassiveDataStream(AutoPassive, "MLSD /", 0)
Command:  EPSV
Response: 229 Entering Extended Passive Mode (|||24505|)
Status:   Connecting to ***:24505
Command:  MLSD /
Response: 150 Ouverture d'une connexion de données en mode BINARY pour MLSD
Status:   FTPS Authentication Successful
Status:   Time to activate encryption: 0h 0m 0s.  Total Seconds: 0,0203418.
+---------------------------------------+
-----------------------------------------
Status:   Disposing FtpSocketStream...

# CloseDataStream()
Response: 425 Impossible d'établir la connexion de données : Opération non permise
Status:   Disposing FtpSocketStream...

# Dispose()
Status:   Disposing FtpClient object...
Command:  QUIT

My code

FtpClient client = new FtpClient(ftpServer, ftpUsername, ftpPassword)
{
    //DataConnectionEncryption = false,
    //DataConnectionType = FtpDataConnectionType.PASV,
    EncryptionMode = FtpEncryptionMode.Explicit,
    // validate any certificate car le certificat du serveur ftp est auto-issu
    ValidateAnyCertificate = true,

};
FtpTrace.EnableTracing = true;
FtpTrace.AddListener(new ConsoleTraceListener());

await client.ConnectAsync();

Console.WriteLine("*** List files ***");
var items =  client.GetListing();
foreach (var item in items)
{
    Console.WriteLine($"> {item}");
}

Tried with data connection encryption to false, but got Response: 522 SSL/TLS requis sur le canal de données response (SSL/TLS required).

Tried with FtpDataConnectionType.PORT, but it times out (Timed out trying to read data from the socket stream!)

Also tried with any FtpDataConnectionType passive mode, but it is the same :(

FileZilla It works well with FileZilla.

Réponse :   220 ProFTPD 1.3.5b Server (xxx.xxx.local)
Commande :  AUTH TLS
Réponse :   234 AUTH TLS exécuté avec succès
Statut :    Initialisation de TLS...
Statut :    Vérification du certificat...
Statut :    Connexion TLS établie.
Commande :  USER ***
Réponse :   331 Mot de passe requis pour ***
Commande :  PASS ************
Réponse :   230 Utilisateur *** authentifié
Commande :  OPTS UTF8 ON
Réponse :   200 UTF-8 activé
Commande :  PBSZ 0
Réponse :   200 PBSZ 0 exécuté avec succès
Commande :  PROT P
Réponse :   200 Protection set to Private
Statut :    Connecté
Statut :    Récupération du contenu du dossier "/"...
Commande :  CWD /
Réponse :   250 Commande CWD exécutée avec succès
Commande :  TYPE I
Réponse :   200 Type paramétré à I
Commande :  PASV
Réponse :   227 Entering Passive Mode (,,,,129,125).
Commande :  MLSD
Réponse :   150 Ouverture d'une connexion de données en mode BINARY pour MLSD
Réponse :   226 Téléchargement terminé
robinrodricks commented 3 years ago

For this reason I created the AutoConnect method. Read up on how it works and it will help you.

maftieu commented 3 years ago

Used AutoConnectAsync() and same result.

# AutoConnectAsync()

# AutoDetect(True)

[skipped many attempt]

# Connect()
Status:   Connecting to ***:21
Response: 220 ProFTPD 1.3.5b Server (***)
Status:   Detected FTP server: ProFTPD
Command:  AUTH TLS
Response: 234 AUTH TLS ex‚cut‚ avec succŠs
Status:   FTPS Authentication Successful
Status:   Time to activate encryption: 0h 0m 0s.  Total Seconds: 0,0525341.
Command:  USER ***
Response: 331 Mot de passe requis pour ***
Command:  PASS ***
Response: 230 Utilisateur *** authentifi‚
Command:  PBSZ 0
Response: 200 PBSZ 0 ex‚cut‚ avec succŠs
Command:  PROT P
Response: 200 Protection set to Private
Status:   Text encoding: System.Text.UTF8Encoding
Command:  OPTS UTF8 ON
Response: 200 UTF-8 activ‚
Command:  SYST
Response: 215 UNIX Type: L8

# Dispose()
Status:   Disposing FtpClient object...
Command:  QUIT
Response: 221 Au revoir.
Status:   Disposing FtpSocketStream...
Status:   Disposing FtpSocketStream...

# ConnectAsync()
Status:   Connecting to ***:21
Response: 220 ProFTPD 1.3.5b Server (***)
Status:   Detected FTP server: ProFTPD
Command:  AUTH TLS
Response: 234 AUTH TLS ex‚cut‚ avec succŠs
Status:   FTPS Authentication Successful
Status:   Time to activate encryption: 0h 0m 0s.  Total Seconds: 0,0219414.
Command:  USER ***
Response: 331 Mot de passe requis pour ***
Command:  PASS ***
Response: 230 Utilisateur *** authentifi‚
Command:  PBSZ 0
Response: 200 PBSZ 0 ex‚cut‚ avec succŠs
Command:  PROT P
Response: 200 Protection set to Private
Command:  FEAT
Response: 211-Features:
Response: CCC
Response: SITE MKDIR
Response: PBSZ
Response: AUTH TLS
Response: MFF modify;UNIX.group;UNIX.mode;
Response: REST STREAM
Response: MLST modify*;perm*;size*;type*;unique*;UNIX.group*;UNIX.mode*;UNIX.owner*;
Response: UTF8
Response: EPRT
Response: SITE SYMLINK
Response: EPSV
Response: SITE UTIME
Response: MDTM
Response: SITE RMDIR
Response: SSCN
Response: TVFS
Response: SITE COPY
Response: MFMT
Response: SIZE
Response: LANG fr-FR.UTF-8*;fr-FR
Response: PROT
Response: 211 Fin
Status:   Text encoding: System.Text.UTF8Encoding
Command:  OPTS UTF8 ON
Response: 200 UTF-8 activ‚
Command:  SYST
Response: 215 UNIX Type: L8
*** List files ***

# GetListing(null, Auto)

# GetWorkingDirectory()
Command:  PWD
Response: 257 "/" est le r‚pertoire courant
Command:  TYPE I
Response: 200 Type param‚tr‚ … I

# OpenPassiveDataStream(PASV, "MLSD /", 0)
Command:  PASV
Response: 227 Entering Passive Mode (,,,,165,143).
Status:   Connecting to ***:42383
Command:  MLSD /
Response: 150 Ouverture d'une connexion de donn‚es en mode BINARY pour MLSD
Status:   FTPS Authentication Successful
Status:   Time to activate encryption: 0h 0m 0s.  Total Seconds: 0,0244425.
+---------------------------------------+
-----------------------------------------
Status:   Disposing FtpSocketStream...

# CloseDataStream()
Response: 425 Impossible d'‚tablir la connexion de donn‚es : Op‚ration non permise
Status:   Disposing FtpSocketStream...

# Dispose()
Status:   Disposing FtpClient object...
Status:   There is stale data on the socket, maybe our connection timed out or you did not call GetReply(). Re-connecting...
Status:   Disposing FtpSocketStream...
Status:   Not sending QUIT because the connection has already been closed.
Status:   Disposing FtpSocketStream...
Status:   Disposing FtpSocketStream...

Full log attached: AutoConnectAsync full log.txt

maftieu commented 3 years ago

@robinrodricks still not working using AutoConnect. Do you have another idea?

maftieu commented 3 years ago

For information, I tested 3 pure .net libraries, none is working: FluentFTP ; CoreFTP, Ftp. I tested 3 desktop programs, all are working.

So I switched to the WinSCP .net wrapper...