Timed out trying to read data from the socket stream!

May 26, 2016 at 8:30 AM
Edited May 31, 2016 at 10:41 AM
Hello,

i connect to a Drftpd Server with SSL.
I can Connect, i can List all Folders and Files.
But i can't Download Files.

My Code:
FtpClient conn = new FtpClient();
            
                
                conn.Host = "192.168.0.72";
                conn.Port = 16542;
                conn.Credentials = new NetworkCredential("Username", "password");
                conn.EncryptionMode = FtpEncryptionMode.Explicit;
                conn.DataConnectionType = FtpDataConnectionType.AutoPassive;
                conn.DataConnectionEncryption = true;
                conn.EnableThreadSafeDataConnections = false;
                conn.ValidateCertificate += new FtpSslValidation(OnValidateCertificate);
                conn.SslProtocols = SslProtocols.Default | SslProtocols.Tls11 | SslProtocols.Tls12;
                conn.Execute("PRET LIST");
                //FtpTrace.AddListener(new System.Diagnostics.ConsoleTraceListener());
                // Datei Download
                foreach (var ftpListItem in conn.GetListing(dir, FtpListOption.Modify | FtpListOption.Size))
                {
                    var destinationPath = string.Format(@"{0}\{1}", @"C:\Users\Autosource\Desktop\test", ftpListItem.Name);
                    conn.SetWorkingDirectory(dir);
                    conn.Execute("PRET RETR "+ftpListItem.Name);
                    conn.Execute("PASV");
                    conn.Execute("RETR " + ftpListItem.Name);
                    Stream ftpStream  = conn.OpenRead(ftpListItem.FullName);
                    
                        using (FileStream fileStream = File.Create(destinationPath, (int)ftpStream.Length))
                        {
                            
                            var buffer = new byte[2 * 1024];
                            int count;
                            while ((count = ftpStream.Read(buffer, 0, buffer.Length)) > 0)
                            {
                                fileStream.Write(buffer, 0, count);
                            }
                        }
                        ftpStream.Close();
                }
            
        }
FTP LOG Trace:
220 New-Record Site
AUTH TLS
234 AUTH TLS successful
Time to activate encryption: 0h 0m 0s, Total Seconds: 0,2590149.
USER *********
331 Password required for ***********.
PASS <omitted>
230- 
230-                       Welcome on
230 ********** logged in successfully.
PBSZ 0
200 Command okay
PROT P
200 Command okay
FEAT
211-Extensions supported:
 MLST type*,x.crc32*,size*,modify*,unix.owner*,unix.group*,x.slaves*,x.xfertime*
 PRET
 AUTH SSL
 PBSZ
 CPSV
 SSCN
 CLNT
 NOOP
211 End
Text encoding: System.Text.ASCIIEncoding
PRET LIST
200 OK, will use master for upcoming transfer
PWD
257 "/" is current directory
TYPE I
200 Command okay
EPSV
500 No command handler for EPSV
PASV
227 Entering Passive Mode (192,168,0,72,173,227).
MLSD /***/crew
150 File status okay; about to open data connection.
Time to activate encryption: 0h 0m 0s, Total Seconds: 0,2130122.
type=file;x.crc32=e17b5328;size=20000000;modify=20160511124054.116;unix.owner=Power;unix.group=iND;x.slaves=N-Record-ARCHiV1;x.xfertime=2350; crew.e29-480p.r03
type=file;x.crc32=913c4cdf;size=5499847;modify=20160511124056.032;unix.owner=Power;unix.group=iND;x.slaves=N-Record-ARCHiV4;x.xfertime=1158; crew.e29-480p.r13
type=file;x.crc32=fa611a12;size=20000000;modify=20160511124056.209;unix.owner=Antonov;unix.group=iND;x.slaves=N-Record-GB2;x.xfertime=1508; crew.e29-480p.r02
type=file;x.crc32=9edfea12;size=20000000;modify=20160511124053.550;unix.owner=Pegasus;unix.group=iND;x.slaves=N-Record-ARCHiV1;x.xfertime=935; crew.e29-480p.r12
type=file;x.crc32=104c332e;size=20000000;modify=20160511124054.953;unix.owner=Power;unix.group=iND;x.slaves=N-Record-GB2;x.xfertime=1424; crew.e29-480p.r01
type=file;x.crc32=d2e59c93;size=20000000;modify=20160511124053.839;unix.owner=Antonov;unix.group=iND;x.slaves=N-Record-ARCHiV5;x.xfertime=1563; crew.e29-480p.r11
type=file;x.crc32=33fb5246;size=20000000;modify=20160511124055.415;unix.owner=str0bi;unix.group=iND;x.slaves=N-Record-ARCHiV5;x.xfertime=1424; crew.e29-480p.r10
type=file;x.crc32=d5c2707b;size=20000000;modify=20160511124055.432;unix.owner=Power;unix.group=iND;x.slaves=N-Record-GB1;x.xfertime=1675; crew.e29-480p.r00
type=file;x.crc32=70b4d9f4;size=6967;modify=20160511124102.187;unix.owner=Buddte;unix.group=iND;x.slaves=N-Record-ARCHiV1;x.xfertime=1208; crew.e29-480p.jpg
type=file;x.crc32=a2cf4847;size=20000000;modify=20160511124052.250;unix.owner=Pegasus;unix.group=iND;x.slaves=N-Record-ARCHiV4;x.xfertime=657; crew.e29-480p.r09
type=file;x.crc32=83dc14e7;size=990;modify=20160511124051.139;unix.owner=Nudged;unix.group=iND;x.slaves=N-Record-ARCHiV1;x.xfertime=19; crew.e29-480p.sfv
type=file;x.crc32=6291d7e7;size=20000000;modify=20160511124052.129;unix.owner=Pegasus;unix.group=iND;x.slaves=N-Record-GB2;x.xfertime=632; crew.e29-480p.r08
type=file;x.crc32=a0d2b5b1;size=20000000;modify=20160511124059.844;unix.owner=sYp;unix.group=iND;x.slaves=N-Record-ARCHiV5;x.xfertime=2116; crew.e29-480p.r07
type=file;x.crc32=ec189349;size=20000000;modify=20160511124055.083;unix.owner=Pegasus;unix.group=iND;x.slaves=N-Record-GB2;x.xfertime=1138; crew.e29-480p.r06
type=file;x.crc32=09085f48;size=20000000;modify=20160511124056.148;unix.owner=Neptun;unix.group=iND;x.slaves=N-Record-ARCHiV2;x.xfertime=2711; crew.e29-480p.r05
type=file;x.crc32=00e32195;size=20000000;modify=20160511124055.017;unix.owner=Power;unix.group=iND;x.slaves=N-Record-ARCHiV3;x.xfertime=3086; crew.e29-480p.r04
type=file;x.crc32=874ca1d0;size=20000000;modify=20160511124052.122;unix.owner=Pegasus;unix.group=iND;x.slaves=N-Record-ARCHiV2;x.xfertime=540; crew.e29-480p.rar
226 Closing data connection
Disposing FtpSocketStream...
crew.e29-480p.r03
crew.e29-480p.r13
crew.e29-480p.r02
crew.e29-480p.r12
crew.e29-480p.r01
crew.e29-480p.r11
crew.e29-480p.nfo
crew.e29-480p.r10
crew.e29-480p.r00
crew.e29-480p.r09
crew.e29-480p.sfv
crew.e29-480p.r08
crew.e29-480p.r07
crew.e29-480p.r06
crew.e29-480p.r05
crew.e29-480p.r04
crew.e29-480p.rar
QUIT
221 Goodbye!
220 New-Record Site
AUTH TLS
234 AUTH TLS successful
Time to activate encryption: 0h 0m 0s, Total Seconds: 0,2110121.
USER **********
331 Password required for ************.
PASS <omitted>
230- 
230-                       Welcome on
230 *********** logged in successfully.
PBSZ 0
200 Command okay
PROT P
200 Command okay
FEAT
211-Extensions supported:
 MLST type*,x.crc32*,size*,modify*,unix.owner*,unix.group*,x.slaves*,x.xfertime*
 PRET
 AUTH SSL
 PBSZ
 CPSV
 SSCN
 CLNT
 NOOP
211 End
Text encoding: System.Text.ASCIIEncoding
CWD /***/Crew
PRET RETR crewE29-480p.r03
200 OK, will use N-Record-ARCHiV1 for upcoming  transfer
PASV
227 Entering Passive Mode (192,168,0,165,3,180).
RETR crewE29-480p.r03
150 File satus okay; about to open data connection from N-Record-ARCHiV1.
TYPE 1
I think that after "PASV", not to the new server connect
Can you please help me with this Problem?
May 31, 2016 at 10:38 AM
Hello again,

i think i have the problem found.

Your DLL builds no data stream to another IP than to the specified in the HOST. If the "PASV" command but a different IP returns should also use this IP data stream.