PrivateKey Property  
 

Gets and sets the private key file used for SSH authentication.

Syntax

object.PrivateKey [= filename ]

Remarks

The PrivateKey property specifies the path to the private key file used to authenticate the user. The private key is used in combination with the value of the UserName property to provide credentials to an SSH server. If public/private key authentication is not required by the server, this property is should be set to an empty string. This property is only used with SFTP connections and is ignored for standard FTP connections or secure connections using FTPS (FTP+TLS).

The PrivateKey property value can use environment variables enclosed in percent symbols, and the path to the private key file will be normalized. It is recommended you always use an absolute path to the private key file. If you do not include a path, it will use the current working directory for the process. This can produce inconsistent results because the current working directory for a process is a global value and it can be changed at any time.

The private key file name must resolve to a text file which can be read by the current process. If the file does not exist, or it does not specify a PEM formatted file which contains an RSA or OpenSSH private key, the connection will fail and the last error code will be set to stErrorInvalidPrivateKey.

Data Type

String

Example

FileTransfer1.ServerType = fileServerFtp
FileTransfer1.Options = fileOptionSecureShell
FileTransfer1.UserName = "username"
FileTransfer1.PrivateKey = "%USERPROFILE%\\.ssh\\id_rsa.pem"
        
nError = FileTransfer1.Connect("file.server.tld", 22)
If nError > 0 Then
    MsgBox FileTransfer1.LastErrorString, vbExclamation
    Exit Sub
End If

In this example, the path to the private key file will be expanded to an absolute path because the USERPROFILE environment variable defines the home directory for the current user.

See Also

Password Property, UserName Property, Connect Method