System.Net.Sockets.SocketException

Nov 20, 2009 at 6:01 PM

Hello,

My Project Description:

I am creating a MLS Feed download and import data in MySQL database project. I already tried FTPWebRequest class of VB.Net 2.0, but it is not suitable for my need because I need to download large files like more than 30MB to 1 GB (memory limit problem because of filestream use to download file). I found Alex FTPS client and tried to integrate in my project, but I am facing an error. My project is a VB.net console application. FTPWebrequest is able to connect server FTP and download files, but it download files upto 22 MB only because of memory limitation problem.

Error:

 

System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 10.10.10.72:2884
   at System.Net.Sockets.TcpClient..ctor(String hostname, Int32 port)
   at AlexPilotti.FTPS.Client.FTPSClient.SetupDataConnection()
   at AlexPilotti.FTPS.Client.FTPSClient.PasvCmd()
   at AlexPilotti.FTPS.Client.FTPSClient.GetFile(String remoteFileName)
   at AlexPilotti.FTPS.Client.FTPSClient.GetFile(String remoteFileName, String localFileName, FileTransferCallback transferCallback)
   at AlexPilotti.FTPS.Client.FTPSClient.GetFile(String remoteFileName, String localFileName)

System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 10.10.10.72:2884

   at System.Net.Sockets.TcpClient..ctor(String hostname, Int32 port)

   at AlexPilotti.FTPS.Client.FTPSClient.SetupDataConnection()

   at AlexPilotti.FTPS.Client.FTPSClient.PasvCmd()

   at AlexPilotti.FTPS.Client.FTPSClient.GetFile(String remoteFileName)

   at AlexPilotti.FTPS.Client.FTPSClient.GetFile(String remoteFileName, String localFileName, FileTransferCallback transferCallback)

   at AlexPilotti.FTPS.Client.FTPSClient.GetFile(String remoteFileName, String localFileName)

 

My Source Code:

Public Shared Sub FTPDownloadTest()

            Using objFTP As New FTPSClient

                objFTP.Connect("FTPHost", New NetworkCredential("UID", "PWD"), ESSLSupportMode.CredentialsRequired Or ESSLSupportMode.DataChannelRequested, New RemoteCertificateValidationCallback(AddressOf ValidateTestServerCertificate))

                objFTP.GetFile("/Data/Active/Actives_323.zip", "C:/MLSFeed/feed/")

            End Using

        End Sub

        Private Shared Function ValidateTestServerCertificate(ByVal sender As Object, ByVal certificate As X509Certificate, ByVal chain As X509Chain, ByVal sslPolicyErrors As SslPolicyErrors) As Boolean

            ' Accept any certificate

            Return True

        End Function

 

Would you be so kind to guide me if Alex FTPS is proper for my need? If yes then can you please help me to fix the error I mentioned above?

 

Thanks in advance,

 

Haresh

 

Coordinator
Nov 20, 2009 at 7:13 PM

Hi Haresh,

 

is 10.10.10.72 the correct server IP address you're connecting to?

some servers behind a NAT respond with their local address (which is unreachable from outside).

Aside that, your code looks fine.

 

Cheers,

Alessandro

 

 

Nov 21, 2009 at 5:22 PM

Hi Alessandro,

Thank you for your reply. I think the IP: 10.10.10.72 is incorrect. Then I tried to connect FTP by correct IP instead of FTP hostname in Filezilla FTP client and it worked fine but not working using Alex FTPS. However I am able to connect FTP by hostname and IP using FTPWebRequest, so I think there is no problem at server end.

Would you be so kind to guide me to resolve this issue.

 

Thanks,

Haresh

Coordinator
Nov 21, 2009 at 6:36 PM

Haresh,

could you please post here the FileZilla log (the FTP instructions that you see on the left pane)?

Please remove from the log any info that you retain private.

 

Cheers,

Alessandro

 

Nov 22, 2009 at 6:53 AM

Hi Alessandro,

Below are the Filezilla FTP log instructions when I connect the server FTP:

 

 

Status: Connecting to 207.203.101.22:21...
Status: Connection established, waiting for welcome message...
Response: 220 sql X2 WS_FTP Server 6.1(22993750)
Command: USER closerealty
Response: 331 Enter password
Command: PASS *****
Response: 230 User logged in
Command: SYST
Response: 215 UNIX
Command: FEAT
Response: 221-Extensions supported
Response:    SIZE
Response:    XMD5
Response:    XSHA1
Response:    XSHA256
Response:    XSHA512
Response:    XQUOTA
Response:    LANG EN, ES, FR, GE
Response:    MDTM
Response:    MLST size*;type*;perm*;create*;modify*;
Response:    REST STREAM
Response:    TVFS
Response:    UTF8
Response:    AUTH SSL;TLS-P;
Response:    PBSZ
Response:    PROT C;P;
Response: 221 end
Status: Connected
Status: Retrieving directory listing...
Command: PWD
Response: 257 "/" is current directory
Command: TYPE I
Response: 200 Transfer mode set to BINARY
Command: PASV
Response: 227 Entering Passive Mode (207,203,101,22,6,169).
Command: LIST
Response: 125 Transferring directory
Response: 226 Transfer completed
Status: Directory listing successful

Status: Connecting to 207.203.101.22:21...

Status: Connection established, waiting for welcome message...

Response: 220 sql X2 WS_FTP Server 6.1(22993750)

Command: USER UID

Response: 331 Enter password

Command: PASS *****

Response: 230 User logged in

Command: SYST

Response: 215 UNIX

Command: FEAT

Response: 221-Extensions supported

Response:    SIZE

Response:    XMD5

Response:    XSHA1

Response:    XSHA256

Response:    XSHA512

Response:    XQUOTA

Response:    LANG EN, ES, FR, GE

Response:    MDTM

Response:    MLST size*;type*;perm*;create*;modify*;

Response:    REST STREAM

Response:    TVFS

Response:    UTF8

Response:    AUTH SSL;TLS-P;

Response:    PBSZ

Response:    PROT C;P;

Response: 221 end

Status: Connected

Status: Retrieving directory listing...

Command: PWD

Response: 257 "/" is current directory

Command: TYPE I

Response: 200 Transfer mode set to BINARY

Command: PASV

Response: 227 Entering Passive Mode (207,203,101,22,6,169).

Command: LIST

Response: 125 Transferring directory

Response: 226 Transfer completed

Status: Directory listing successful

 

Please let me know if you need more information. I tried to use ESSLSupportMode.Implicit and IP instead of hostname, in this case error is same but its showing correct IP in error, however port is incorrect. Here is the error details:

System.Net.Sockets.SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 207.203.101.22:990 at System.Net.Sockets.TcpClient..ctor(String hostname, Int32 port)

   at AlexPilotti.FTPS.Client.FTPSClient.SetupCtrlConnection(String hostname, Int32 port, Encoding textEncoding)

   at AlexPilotti.FTPS.Client.FTPSClient.Connect(String hostname, Int32 port, NetworkCredential credential, ESSLSupportMode sslSupportMode, RemoteCertificateValidationCallback userValidateServerCertificate, X509Certificate x509ClientCert, Int32 sslMinKeyExchangeAlgStrength, Int32 sslMinCipherAlgStrength, Int32 sslMinHashAlgStrength, Nullable`1 timeout)

   at AlexPilotti.FTPS.Client.FTPSClient.Connect(String hostname, NetworkCredential credential, ESSLSupportMode sslSupportMode, RemoteCertificateValidationCallback userValidateServerCertificate)

   at DownloadGAFeed.DownloadGAFeed.DownloadGAFeed.FTPDownloadTest() in D:\Projects\Georgia MLS\DownloadGAFeed\DownloadGAFeed\DownloadGAFeed.vb:line 383

   at DownloadGAFeed.DownloadGAFeed.DownloadGAFeed.Main(String[] args) in D:\Projects\Georgia MLS\DownloadGAFeed\DownloadGAFeed\DownloadGAFeed.vb:line 32

 

Thanks,

Haresh

 

 

Coordinator
Nov 22, 2009 at 3:02 PM

Haresh,

your FileZilla log shows standard FTP commands without SSL/TLS support.

In this case the correct parameters are:

 

client.Connect("207.203.101.22", 
                     new NetworkCredential("yourUsername", 
                                                       "yourPassword"), 
                     ESSLSupportMode.ClearText);

 

 

 Let me know it this helps!

Cheers,

Alessandro

 

Nov 22, 2009 at 3:38 PM

Hi Alessandro,

I changed my code as per your suggestions, but facing below error:


AlexPilotti.FTPS.Common.FTPCommandException: Transfer cancelled

   at AlexPilotti.FTPS.Client.FTPSClient.GetReply()

   at AlexPilotti.FTPS.Client.FTPSClient.<EndStreamCommand>b__1()

   at AlexPilotti.FTPS.Common.FTPStream.Close()

   at System.IO.Stream.Dispose()

   at AlexPilotti.FTPS.Client.FTPSClient.GetFile(String remoteFileName, String localFileName, FileTransferCallback transferCallback)

   at AlexPilotti.FTPS.Client.FTPSClient.GetFile(String remoteFileName, String localFileName)

   at DownloadGAFeed.DownloadGAFeed.DownloadGAFeed.FTPDownloadTest() in D:\Projects\Georgia MLS\DownloadGAFeed\DownloadGAFeed\DownloadGAFeed.vb:line 393

   at DownloadGAFeed.DownloadGAFeed.DownloadGAFeed.Main(String[] args) in D:\Projects\Georgia MLS\DownloadGAFeed\DownloadGAFeed\DownloadGAFeed.vb:line 33

Thanks,
Haresh

 

Test
AlexPilotti.FTPS.Common.FTPCommandException: Transfer cancelled
   at AlexPilotti.FTPS.Client.FTPSClient.GetReply()
   at AlexPilotti.FTPS.Client.FTPSClient.<EndStreamCommand>b__1()
   at AlexPilotti.FTPS.Common.FTPStream.Close()
   at System.IO.Stream.Dispose()
   at AlexPilotti.FTPS.Client.FTPSClient.GetFile(String remoteFileName, String l
ocalFileName, FileTransferCallback transferCallback)
   at AlexPilotti.FTPS.Client.FTPSClient.GetFile(String remoteFileName, String l
ocalFileName)
   at DownloadGAFeed.DownloadGAFeed.DownloadGAFeed.FTPDownloadTest() in D:\Proje
cts\Georgia MLS\DownloadGAFeed\DownloadGAFeed\DownloadGAFeed.vb:line 393
   at DownloadGAFeed.DownloadGAFeed.DownloadGAFeed.Main(String[] args) in D:\Pro
jects\Georgia MLS\DownloadGAFeed\DownloadGAFeed\DownloadGAFeed.vb:line 33

 

Nov 24, 2009 at 4:57 PM

 

 

Using objFTP As New FTPSClient

                objFTP.Connect(strHost, New NetworkCredential(strUserName, strPassword), ESSLSupportMode.ClearText)
                objFTP.GetFile(strDirectoryName & "/" & strFileName, strSaveDirectoryPath & strFileName)
                objFTP.Close()
            End Using

Hi Alessandro,

Thank you very much for your help. I missed to provide file name in local save path. Now it is working fine with below code:


Using objFTP As New FTPSClient

objFTP.Connect(strHost, New NetworkCredential(strUserName, strPassword), ESSLSupportMode.ClearText)

objFTP.GetFile(strDirectoryName & "/" & strFileName, strSaveDirectoryPath & strFileName)

objFTP.Close()

End Using

 

But I am facing below error after downloading 22, 955KB of the file. This was happening using FTPWebRequest class also.

 

System.IO.IOException: Unable to read data from the transport connection: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ---> System.Net.Sockets.SocketException: A connection attemptfailed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond

   at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)

   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)

   --- End of inner exception stack trace ---

   at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)

   at System.IO.StreamReader.ReadBuffer()

   at System.IO.StreamReader.ReadLine()

   at AlexPilotti.FTPS.Client.FTPSClient.GetReply()

   at AlexPilotti.FTPS.Client.FTPSClient.<EndStreamCommand>b__1()

   at AlexPilotti.FTPS.Common.FTPStream.Close()

   at System.IO.Stream.Dispose()

   at AlexPilotti.FTPS.Client.FTPSClient.GetFile(String remoteFileName, String localFileName, FileTransferCallback transferCallback)

   at AlexPilotti.FTPS.Client.FTPSClient.GetFile(String remoteFileName, String localFileName)

   at DownloadGAFeed.DownloadGAFeed.DownloadGAFeed.DownloadFile(String strHost,String strPort, String strUserName, String strPassword, String strDirectoryName, String strFileName, Int32 intTimeout, String strSaveDirectoryPath)

   at DownloadGAFeed.DownloadGAFeed.DownloadGAFeed.Main(String[] args)

Can you please guide me what could be the problem?
Thanks,
Haresh

Dec 4, 2009 at 4:16 PM

Hello,

Can anyone help me here please?

 

Thanks,

Haresh

 

Coordinator
Dec 4, 2009 at 6:02 PM

Haresh,

there is no such limit in AlexFTPS.

I assume that your not using FAT32 filesystems.

Do you experience the same behaviour using the FileZilla client?

Googling around it seems there are a few people experiencing the same problem with WS_FTP servers.

 

Cheers,

Alessandro