Establish secured connection with Port number as input

May 10, 2012 at 6:43 AM

Hi,

 

  I am currently using the AlexPilotti.FTPS.Client library to connect to an FTPS server, I can connect to it successfully and perform ftps command with no problem at all (i.e. FTPPut, FTPGet, FTPList and etc.).

  My connect() argument is something like this: 

ftp.Connect(hostName, new NetworkCredential(userName,                                     password),               ESSLSupportMode.CredentialsRequired |               ESSLSupportMode.DataChannelRequested, new RemoteCertificateValidationCallback(ValidateCertificate));

  What I wanted to achieve is to specify a Port number on my connect argument but disregarding the other parameters of the connect function (i.e. x509ClientCert, sslMinKeyExchangeAlgStrength, sslMinCipherAlgStrength, sslMinHashAlgStrength, int? timeout.)

  Is this possible?

 

Thanks.

May 15, 2012 at 10:36 AM

Hi,

 

 

  Just for an update, I've seen in your source code that you have hard-coded the values for the port on one of the Connect() function, is it possible that the assignment of the port connect to will come from the user?

 

  I tried to use this function instead 

ftp.Connect("192.168.1.100", 990, new NetworkCredential("someuser", "somepass"), sslSupportMode, new RemoteCertificateValidationCallback(ValidateCertificate), null, 0, 0, 0, 80000);

 

  but I am getting this exception:

System.ArgumentNullException: Value cannot be null.
Parameter name: input
   at System.Text.RegularExpressions.Regex.Match(String input)
   at System.Text.RegularExpressions.Regex.Match(String input, String pattern)
   at AlexPilotti.FTPS.Client.FTPSClient.GetReply()
   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, Boolean useCtrlEndPointAddressForData, EDataConnectionMode dataConnectionMode)
   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, Boolean useCtrlEndPointAddressForData)
   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 FTPHandlerWebService.FTPHandlerWebService.FTPSList(String remoteDirectory) in C:\Users\User\Documents\Visual Studio 2008\Projects\FTPHandlerService\FTPHandlerWebService\FTPHandlerService.asmx.cs:line 118

 

  What am I missing?

 

Thanks.

May 16, 2012 at 9:15 AM

Problem solved! 

Used the following Connect() argument, 

auth = new NetworkCredential(userName, password);
            ftp.Connect(hostName, port, auth,                    AlexPilotti.FTPS.Client.ESSLSupportMode.Implicit, new RemoteCertificateValidationCallback(ValidateCertificate),                    null, 0, 0, 0, timeout);