biz.neustar.wpm.api
Interface Ftp


public interface Ftp

FTP monitoring API

To include in a script add the following to the top of the script file.

 var ftp = require('ftp');
 
Example that logs in and verifies that a known file can be downloaded.
 var ftp = require('ftp');

 test.beginTransaction();
 test.beginStep();
 ftp.connect("ftp.servername.com");
 ftp.login("username", "password");
 ftp.setBinary(true);
 ftp.get("status_check.txt");
 ftp.quit();
 test.endStep();
 test.endTransaction();
 


Method Summary
 void cd(java.lang.String directory)
          Change current remote directory
 void connect(java.lang.String hostname)
          Connect to the given server
 void connect(java.lang.String hostname, int port)
          Connect to the given server and port
 void connectSSL(java.lang.String hostname, boolean implicit)
          Connect to the given ftps server
 void connectSSL(java.lang.String hostname, int port, boolean implicit)
          Connect to the given ftps server
 void enableLogging()
          Enable logging of Ftp commands and responses to the
 Bytes get(java.lang.String filename)
          Download the given filename.
 java.lang.String getLastResponse()
          Returns the last response from the Ftp server.
 void login(java.lang.String username, java.lang.String password)
          Login with the given username and password
 int quit()
          Quit the session and disconnect from the server
 void setActive(boolean active)
          Sets active Ftp mode for file transfers.
 void setBinary(boolean binary)
          Set the Ftp filemode to binary or back to ASCII.
 

Method Detail

connect

void connect(java.lang.String hostname)
             throws java.lang.Exception
Connect to the given server

Parameters:
hostname - the FTP server to connect to
Throws:
java.lang.Exception - when unable to connect to the server or when a timeout occurs.

connect

void connect(java.lang.String hostname,
             int port)
             throws java.lang.Exception
Connect to the given server and port

Parameters:
hostname - the FTP server to connect to
port - the port to connect to
Throws:
java.lang.Exception - when unable to connect to the server or when a timeout occurs.

connectSSL

void connectSSL(java.lang.String hostname,
                boolean implicit)
                throws java.lang.Exception
Connect to the given ftps server

Both implicit and explicit ftps are supported.

When implicit is specified the default port is 990.

When explicit is specified (implicit set to false) the default port is 21.

Parameters:
hostname - the ftps server to connect to
implicit - when set to true ftps implicit mode is used. This means the connection is made over SSL. When set to false ftps explicit mode is used. This means the connection starts off as a normal Ftp connection and then is later upgraded to SSL (before the username and password are sent of course).
Throws:
java.lang.Exception - when unable to connect to the server or when a timeout occurs.

connectSSL

void connectSSL(java.lang.String hostname,
                int port,
                boolean implicit)
                throws java.lang.Exception
Connect to the given ftps server

Parameters:
hostname - the ftps server to connect to
port - the port to connect to
implicit - when set to true ftps implicit mode is used. This means the connection is made over SSL. When set to false ftps explicit mode is used. This means the connection starts off as a normal Ftp connection and then is later upgraded to SSL (before the username and password are sent of course).
Throws:
java.lang.Exception - when unable to connect to the server or when a timeout occurs.

login

void login(java.lang.String username,
           java.lang.String password)
           throws java.lang.Exception
Login with the given username and password

Parameters:
username - the username to login with
password - the password to login with
Throws:
java.lang.Exception - if unable to login to the server with the given username/password or if the connection is lost.

quit

int quit()
         throws java.lang.Exception
Quit the session and disconnect from the server

Returns:
the Ftp status code returned by calling Ftp quit.
Throws:
java.lang.Exception - when the connection lost or quit command is rejected.

cd

void cd(java.lang.String directory)
        throws java.lang.Exception
Change current remote directory

Parameters:
directory - the remote directory to cd into
Throws:
java.lang.Exception - when the connection to the server is lost, or the directory does not exist.

get

Bytes get(java.lang.String filename)
          throws java.lang.Exception
Download the given filename. Maximum file size that will be downloaded is 2097152. Files are downloaded as ASCII by default, call
setBinary(true)
to enable binary mode. Files are downloaded in passive mode by default, so passive mode is expected to be supported by the server. Call
setActive(true)
to switch to doing file downloads in active mode.

Parameters:
filename - the filename to download
Returns:
bytes of the file
Throws:
java.lang.Exception - when the file exceeds the maximum size, or the file cannot be found.

setBinary

void setBinary(boolean binary)
               throws java.lang.Exception
Set the Ftp filemode to binary or back to ASCII.

Parameters:
binary - set to true for binary file downloads, false for ASCII.
Throws:
java.lang.Exception - when the connection to the server is lost, or won't accept binary mode.

setActive

void setActive(boolean active)
               throws java.lang.Exception
Sets active Ftp mode for file transfers.

By default passive file transfers are used. Passive transfers require a listening port on the server to be opened by the Ftp server every time a file is downloaded. Active transfers open the listening port on the client. For active transfers to work usually some kind of NAT has to be in place, on our network some locations may not have a NAT in place (Usually Cloud Compute providers don't). For this reason we recommend sticking with the default and only doing passive transfers. Contact support for a list of locations if you must use active mode.

Parameters:
active - set to true for active file downloading, false for passive file downloading.
Throws:
java.lang.Exception - when the connection to the server is lost, or won't accept the passive/active mode specified.

getLastResponse

java.lang.String getLastResponse()
Returns the last response from the Ftp server.

Returns:
the last string response from the Ftp server

enableLogging

void enableLogging()
Enable logging of Ftp commands and responses to the
test.log()
output.


Copyright © 2014 Neustar, Inc. All Rights Reserved.