SecureFTPConnectionConnect Method |
Namespace: EnterpriseDT.Net.Ftp
If this component is being used on a form or within another component then it is a good idea to use the "Connection Tester" to test the property settings.
Connections are not opened until the Connect method is called. Connection-, Authentication-, and Security-related properties should be set prior to opening the connection.
At a minimum, the following properties should be set prior to connection.
Property | Description |
---|---|
Protocol | The protocol to use: SFTP, explicit FTPS, implicit FTPS or plain FTP. |
ServerAddress | The domain-name or IP-address of the server. |
UserName | User-name of account on the server. |
Password | Password of account on the server. |
FTPS: If explicit FTPS has been selectedand AutoSecure is true (the default) then the component will try to secure the connection immediately after successfully connecting. A secure connection will always be attempted in implicit FTPS is selected regardless of the value of AutoSecure.
SecureFTPConnection ftp = new SecureFTPConnection(); ftp.Protocol = FileTransferProtocol.FTPSExplicit; ftp.ServerAddress = "my-server-name"; ftp.UserName = "my-username"; ftp.Password = "my-password"; ftp.ServerValidation = SecureFTPServerValidationType.Automatic; // the server's certificate must have been previously registered with // the operating system (see class description) ftp.Connect(); ftp.Close();
SFTP: SFTP connections always require some kind of authentication; this may be set using the AuthenticationMethod property. Server validation is optional, but recommended; it is selected using the ServerValidation property.
SecureFTPConnection ftp = new SecureFTPConnection(); ftp.Protocol = FileTransferProtocol.SFTP; ftp.ServerAddress = "my-server-name"; ftp.UserName = "my-username"; ftp.Password = "my-password"; ftp.AuthenticationMethod = AuthenticationType.Password; ftp.ServerValidation = SecureFTPServerValidationType.None; ftp.Connect(); ftp.Close();
SecureFTPConnection ftp = new SecureFTPConnection(); ftp.Protocol = FileTransferProtocol.SFTP; ftp.ServerAddress = "my-server-name"; ftp.UserName = "my-username"; ftp.AuthenticationMethod = AuthenticationType.PublicKey; ftp.ClientPrivateKeyFile = "pathtokeyfile"; ftp.ClientPrivateKeyPassphrase = "passwordforkeyfile"; ftp.ServerValidation = SecureFTPServerValidationType.None; ftp.Connect(); ftp.Close();
This method will throw an FTPException if the component is already connected to the server.