|
How to use FTPS (with client/server validation)
|
|
IMPORTANT: An FTPS compatible FTP server is required for this example. There are free
FTPS-compatible servers available on Windows and *NIX platforms.
SecureFTPConnection may be configured such that it presents a client certificate upon
request from the server. Note that the server will usually only request the client certificate if it
has been configured to do so. In addition, the server will validate the client certificate in a
manner similar to the way the client validates the server. This is, however, a server
configuration issue and will not be covered here and we will simply assume that the server is
able to validate the client's certificate.
SSLFTPCertificate clientCertificate =
SSLFTPCertificate.PromptForCertificate(form, true);
This call shows appropriate dialogs for loading a certificate and a private key. Since the
private key is password-protected a password prompt will also be displayed. If the flag is false
then no private key will be loaded.
If no user interface is required then a certificate may be loaded as follows:
SSLFTPCertificate clientCertificate =
SSLFTPCertificate.CreateFromPEM(certFileName);
clientCertificate.AssociatePrivateKey(prvKeyFileName, password);
Once a client certificate has been loaded it may be used with the SecureFTPConnection:
ftpConnection.ClientCertificate = clientCertificate;
Note that there is no need to load the client certificate into the certificate store on the machine
on which SecureFTPConnection is being used.
Note also that developers often experience problems when trying to load a private key from a
Windows Service. The topic, Private Key Access Problems, discusses this issue.