Connect to Remote Sites With FTP Automation Component

May 17th, 2014 by Rossy Guide

Establishing a connection

To initiate a connection to a remote host, the address of the host, username and password must be set before calling the corresponding connection command. The Host method is used to set the host address. The HostEnc method is used to set an encrypted value for the host address. The User method is used to set the username. The UserEnc method is used to set an encrypted value for the username. The Pass method is used to set the password for the user account. The PassEnc method is used to set an encrypted value for the password.

The FTPConnect method can be used to establish a regular FTP connection with the remote host. The default port is 21. A different port can be explicitly specified if needed. The FTPConnectSSL method is used to establish an explicit secure FTPS connection while the FTPConnectSSLI method can be used to establish an implicit secure FTPS connection. The FTPConnectSSH method can be used to establish a secure SSH connection. IDL Definition of methods to establish connection with a remote host is shown below.

  HRESULT Host    ([in] BSTR b_hostname);HRESULT HostEnc ([in] BSTR b_hostname_enc);HRESULT User    ([in] BSTR b_username);

HRESULT UserEnc ([in] BSTR b_username_enc);

HRESULT Pass    ([in] BSTR b_password);

HRESULT PassEnc ([in] BSTR b_password_enc);

 

HRESULT FTPConnect     ([in, defaultvalue(21)] UINT n_port);

HRESULT FTPConnectSSL  ([in, defaultvalue(21)] UINT n_port);

HRESULT FTPConnectSSLI ([in, defaultvalue(990)] UINT n_port);

HRESULT FTPConnectSSLC ([in, defaultvalue(21)] UINT n_port);

HRESULT FTPConnectSSH  ([in, defaultvalue(22)] UINT n_port);

 

 

Example usage of methods to establish connection with a remote host (VBScript) is shown below.

app.Host = "localhost" 'hostname or IP address of remote site
app.User = "test"      'account username
app.Pass = "test"      'password for account

app.FTPConnect         'connect to site (default port is 21 for)
app.FTPConnectSSH 27   'connect to site using SFTP on port 27

 

 

The FTPDisconnect method can be used to disconnect from the remote host. The IDL Definition of method to disconnect from a remote host is shown below.


HRESULT FTPDisconnect ();

 

 

Example usage of method to disconnect from a remote host (VBScript) is shown below.


'disconnect from the remote site
app.FTPDisconnect

 

 

Checking connection status

The IsFTPSuccess method can be used to check the status of any method that begins with FTP. This method can be used to check if the connection to the remote host was successful. IDL Definition of method to check status of methods that starts with FTP is shown below.

HRESULT IsFTPSuccess ([out, retval] VARIANT_BOOL *f_is_success);

 

 

Example usage of method to check status of methods that starts with FTP (VBScript) is shown below.


'check if the connection was successful
If app.IsFTPSuccess Then
  'connection was successful
End If

 

 

Setting Local and Remote paths

The FTPSetPath method can be used to set the current local or remote paths by using the “local” or “remote” keywords and specifying the path name to be set. The IDL Definition of method to set local and remote paths is shown below.

HRESULT FTPSetPath ([in] BSTR b_localremote, [in] BSTR b_path);

 

 

Example usage of method to set local and remote paths (VBScript) is shown below.


'set the local and remote paths
app.FTPSetPath "local", "c:\\tmp"
app.FTPSetPath "remote", "/"

 

 

Public key authentication for SSH

The PKeyLoad method can be used to load a private key for passwordless login when connecting to a SSH based SFTP server. The name of the key file and the passphrase used to protect the private key must be provided. The IDL Definition of method to load SSH private key is shown below.

HRESULT PkeyLoad ([in] BSTR b_keyfile, [in, defaultvalue("")]
BSTR b_passphrase);

 

 

Example usage of method to load SSH private key (VBScript) is shown below.


'load private key for SSH public key authentication
app.PkeyLoad "c:\\myprivkey.pem", "mypassphrase"

 

 

Leave a Reply