Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connecting to FTPS (FTP over SSL) with FluentFTP

I am using IIS in my local machine for testing FTP with SSL connection. I am using the FluentFTP library for connecting to the FTP. I am using the following code to connect to the Server.

FtpClient conn = new FtpClient();
conn.Host = firewallSslDetails.Address;
conn.Credentials = new NetworkCredential(firewallSslDetails.UserName, firewallSslDetails.Password);
conn.SslProtocols = System.Security.Authentication.SslProtocols.Default;

X509Certificate2 cert = new X509Certificate2(@"C:\Users\BizTalk360\Desktop\FtpSites\ServerCert.cer");
conn.EncryptionMode = FtpEncryptionMode.Implicit;
conn.DataConnectionType = FtpDataConnectionType.AutoActive;
conn.DataConnectionEncryption = true;
conn.EnableThreadSafeDataConnections = false;
conn.ClientCertificates.Add(cert);
conn.ValidateCertificate += new FtpSslValidation(OnValidateCertificate);

conn.Connect();

The server is returning me with the following error.

FluentFTP.FtpCommandException: Policy requires SSL.; Win32 error: Access is denied.; Error details: SSL policy requires SSL for control channel.;

For connecting over FTP the above code is working fine and for FTP with SSL it is not working.

like image 524
Jothi Prakash Anandan Avatar asked Feb 09 '17 07:02

Jothi Prakash Anandan


People also ask

What version of TLS does FTPS use?

FTPS stands for file transfer protocol SSL (secure sockets locker). SSL is a cryptographic protocol that encrypts the data being transferred. The term SSL is generally used interchangeably with TLS or transport layer security, with TLS v1.

What port does FTP over SSL use?

FTP with explicit SSL/TLS uses the same port (21) for both unsecured and secured services. FTP clients connect to port 21 to establish a control connection that is initially unsecured.


1 Answers

As you seem to be connecting to the default port 21 (no explicit port specified anywhere), you need to use the "Explicit" mode:

conn.EncryptionMode = FtpEncryptionMode.Explicit;

If the server uses a self-signed certificate, you may need to verify it programmatically. Do not blindly accept any certificate, as the answer by @Ivan does. That's a security flaw. Validate the specific certificate, e.g. by checking its fingerprint.

See FtpWebRequest "The remote certificate is invalid according to the validation procedure".

like image 63
Martin Prikryl Avatar answered Sep 16 '22 18:09

Martin Prikryl