Connection succesfull - other commands fail

Nov 30, 2010 at 7:55 AM

Hi,

Could you please assit me with the following: My connection seems to suceed but any subsequent commands fail.

Thanks in Advance

Bo.jangles

My Code:

 

        Using FTP As New AlexPilotti.FTPS.Client.FTPSClient
            Dim credentials As System.Net.NetworkCredential = New System.Net.NetworkCredential("Dog", "Cat")

            Try
                'FTP.Connect("MyURI", 990, credentials, AlexPilotti.FTPS.Client.ESSLSupportMode.Implicit, _
                '            New System.Net.Security.RemoteCertificateValidationCallback(AddressOf ValidateCertificate), _
                '            New System.Security.Cryptography.X509Certificates.X509Certificate(), 0, 0, 0, 30)

                FTP.Connect("XX.XXX.X.XXX", credentials, AlexPilotti.FTPS.Client.ESSLSupportMode.Implicit, _
                            New System.Net.Security.RemoteCertificateValidationCallback(AddressOf ValidateCertificate))

                Dim dir As IList(Of AlexPilotti.FTPS.Common.DirectoryListItem) = FTP.GetDirectoryList()
            Catch ex As Exception
                MsgBox(ex.ToString())
            End Try
        End Using

    Public Function ValidateCertificate(ByVal sender As Object, _
                                        ByVal certificate As X509Certificate, _
                                        ByVal chain As X509Chain, _
                                        ByVal sslPolicyErrors As Security.SslPolicyErrors) As Boolean
        MsgBox("Certificate")
        Return True
    End Function

 

The program goes through the Connect (Including ValidateCertificate) statement and fails on the GetDirectoryList. I've tried many combinations for the ESSLSupportMoce but only implicit gets me beyond Connect.

After connect I inspect the FTP object:

? ftp
{AlexPilotti.FTPS.Client.FTPSClient}
    BannerMessage: "Microsoft FTP Service"
    LocalCertificate: Nothing
    RemoteCertificate: {System.Security.Cryptography.X509Certificates.X509Certificate}
    SslInfo: {Tls, Aes128 (128 bit), RsaKeyX (2048 bit), Sha1 (160 bit)}
    SslSupportCurrentMode: Implicit {63}
    SslSupportRequestedMode: Implicit {63}
    TextEncoding: UTF8 {1}
    TransferMode: Binary {1}
    WelcomeMessage: "Directory has 95,475,625,984 bytes of disk space available.  User logged in."

when I let the program go to GetDirectoryList I get the following error after 5-10 seconds:

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 192.168.156.16:65515"}

Please note that 192.168.156.16 is not the XX.XXX.X.XXX address that I 'm connecting to. It is obviously a local server address.

 

The scarse documentation that I have to connect to this server states:

TCP port 990 using pasive mode

return ports 65515 to 65535 (I've opened thes ports on the firewall and tried without the firewall)

 

Filezilla works without a problem:

Status: Resolving address of MyURI
Status: Connecting to XX.XXX.X.XXX:990...
Status: Connection established, initializing TLS...
Status: Verifying certificate...
Status: TLS/SSL connection established, waiting for welcome message...
Response: 220 Microsoft FTP Service
Command: USER Dog
Response: 331 Password required for Dog.
Command: PASS **********
Response: 230-Directory has 71,383,121,920 bytes of disk space available.
Response: 230 User logged in.
Command: SYST
Response: 215 Windows_NT
Command: FEAT
Response: 211-Extended features supported:
Response:  LANG EN*
Response:  UTF8
Response:  AUTH TLS;TLS-C;SSL;TLS-P;
Response:  PBSZ
Response:  PROT C;P;
Response:  CCC
Response:  HOST
Response:  SIZE
Response:  MDTM
Response:  REST STREAM
Response: 211 END
Command: OPTS UTF8 ON
Response: 200 OPTS UTF8 command successful - UTF8 encoding now ON.
Command: PBSZ 0
Response: 200 PBSZ command successful.
Command: PROT P
Response: 200 PROT command successful.
Status: Connected
Status: Retrieving directory listing...
Command: PWD
Response: 257 "/" is current directory.
Command: TYPE I
Response: 200 Type set to I.
Command: PASV
Response: 227 Entering Passive Mode (192,168,156,16,255,244).
Status: Server sent passive reply with unroutable address. Using server address instead.
Command: LIST
Response: 150 Opening BINARY mode data connection.
Response: 226-Directory has 71,383,121,920 bytes of disk space available.
Response: 226 Transfer complete.
Status: Directory listing successful

 

 

 

Dec 9, 2010 at 2:43 PM

Hi,

I have found the solution. I've checked the source code and found the parmater for connect command that does the trick:

/// <param name="useCtrlEndPointAddressForData"><c>true</c> to use the control channel remote address for data connections instead of the address returned by PASV</param>

This parameter was missing from the version I had although it is the same version 1.0.2.0

Setting this parameter to true forces the FTP client to use the server address established during the connection and not the one returned by PASV command. The address returned by PASV is unroutable because it refers to a server's local network address e.g. 192.168.156.16:65515.

All above is for implicit connection which I'm using.

Thanks

bojangles

 

Coordinator
Dec 9, 2010 at 3:34 PM

Hi Bojangles,

thanks for sharing your solution!

 

Alessandro Pilotti

[ MVP / IIS ]

May 18, 2011 at 9:10 PM
bojangles wrote:

Hi,

I have found the solution. I've checked the source code and found the parmater for connect command that does the trick:

/// <param name="useCtrlEndPointAddressForData"><c>true</c> to use the control channel remote address for data connections instead of the address returned by PASV</param>

This parameter was missing from the version I had although it is the same version 1.0.2.0

Setting this parameter to true forces the FTP client to use the server address established during the connection and not the one returned by PASV command. The address returned by PASV is unroutable because it refers to a server's local network address e.g. 192.168.156.16:65515.

All above is for implicit connection which I'm using.

Thanks

bojangles

 


This is fantastic! I had found the FTPS Client on a task assigned form my Boss. This solution would make the tool fit our needs perfectly! Being an "unseasoned" coder, is there anyway you can assist me with "how" to implement this solution?

I (and my boss) would be truly grateful.

Thanks,

Rick

Coordinator
May 19, 2011 at 3:46 AM

Hi Rick,

the useCtrlEndPointAddressForData is just the last parameter of one of the Connect method overloads. Set it to true and you are done :-)

 

Cheers,

Alessandro Pilotti

[ MVP / IIS ]

Jun 21, 2011 at 1:45 PM

Hi,

I am also facing the same problem.

 

My question is can you provide me the dll link which will help us to include the parameter which you had mentioned above in Connect method of FTP.

 

 

Any quick solution will be highly appreciated.

 

 

Thanks & Regards,

Hirak

Jun 21, 2011 at 2:22 PM

Download the Alex FTPS Client from

http://ftps.codeplex.com/releases/view/21961#DownloadId=55420

The DLL version I am using is 1.0.2.31196. Bear in mind that my first attempt was also with 1.0.2 but the build number was different and that version didn’t have the required parameter.

Regards

Bojan

From: hiraks [email removed]
Sent: Tuesday, June 21, 2011 3:45 PM
To: bkuhar@telkomsa.net
Subject: Re: Connection succesfull - other commands fail [ftps:236482]

From: hiraks

Hi,

I am also facing the same problem.

My question is can you provide me the dll link which will help us to include the parameter which you had mentioned above in Connect method of FTP.

Any quick solution will be highly appreciated.

Thanks & Regards,

Hirak

Jun 21, 2011 at 2:33 PM

Hi,

Thanks for your quick reply.

But, unfortunately after downloading the dll from your link, the version what I can see is 1.0.2.27845.

Please, let me know whether the path which you had mentioned is correct or wrong.

Thanks & Regards,

Hirak

Jun 21, 2011 at 3:01 PM

Hi,

I remember now, I’ve downloaded the latest source code and recompiled it. I don’t think that I have done any changes to the source code.

http://ftps.codeplex.com/SourceControl/list/changesets#

Regards

Bojan

From: hiraks [email removed]
Sent: Tuesday, June 21, 2011 4:33 PM
To: bkuhar@telkomsa.net
Subject: Re: Connection succesfull - other commands fail [ftps:236482]

From: hiraks

Hi,

Thanks for your quick reply.

But, unfortunately after downloading the dll from your link, the version what I can see is 1.0.2.27845.

Please, let me know whether the path which you had mentioned is correct or wrong.

Thanks & Regards,

Hirak

Coordinator
Jun 21, 2011 at 3:18 PM

Hi Hirak,

can you please check if the lastest binary version you downloaded contains the parameter you're looking for?

Otherwise I'll compile the lastest one for you from the sources.

 

Cheers,

Alessandro Pilotti

[ MVP / IIS ]  

 

Jun 21, 2011 at 3:23 PM

Hi Alessandro,

 

No it does not.

 

Please, resend me the dll after you compile with the added parameter in it.

 

Quick reply will be appreciated.

 

 

Thanks & Regards,

Hirak

Jun 22, 2011 at 10:21 AM

Hi Alessandro,

 

Any updates on the latest dll which you had mentioned you will send with the added parameter.

 

Thanks & Regards,

Hirak

 

Coordinator
Jun 22, 2011 at 6:37 PM

Hirak,

please try this version and let me know if it works for you.

 

Cheers,

Alessandro Pilotti

[ MVP/ IIS ]

 

 

 

Coordinator
Jul 3, 2011 at 8:19 PM

Hirak,

here's a copy of the latest 1.1 release beta 1. The parameter you requested has been added to the command line interface too.

 

Cheers,

Alessandro

 

Jul 4, 2011 at 8:55 AM

Hi Alessandro,

 

Thanks for your mail.

 

It worked fine.

Thanks a lot for your instant support.

 

With Regards,

Hirak

Coordinator
Jul 4, 2011 at 10:43 AM

Excellent :-)

Cheers,

Alessandro

Jun 16, 2014 at 4:55 PM
Hi Alessandro

I have exactly the same problem now with a new project and version 1.1.0.
When I read descriptions of context, error and errormessages all is very similar.

I use the dll in a VB.NET project.

ftps is defined as FTPSClient before this code:

ftps = New FTPSClient()
Dim auth As New NetworkCredential(username, password)
ftps.Connect(address, 990, auth, AlexPilotti.FTPS.Client.ESSLSupportMode.Implicit, New RemoteCertificateValidationCallback(AddressOf ValidateServerCertificate), Nothing, 0, 0, 0, Nothing, True)

I can connect without problems but not get beyond GetDirectoryList()
I tried the connect method after reading about the useCtrlEndPointAddressForData parameter, but it dis not help.

Any ideas where to start?

Regards Jorgen