Default properties and methods of
the FtpClient prototype.
Constructor for File objects, to send and receive files from an FTP server.
The FTP client needs Daniel Savarese's NetComponents library in the classpath in order to work.
Example:
The FTP client needs Daniel Savarese's NetComponents library in the classpath in order to work.
Example:
var ftp = new FtpClient("ftp.mydomain.com");
parameters
String | server | as String, the address of the FTP Server to connect to |
methods
- ascii()
- binary()
- cd(dir)
- getFile(source, dest)
- getString(source)
- lcd(dir)
- login(username, password)
- logout()
- mkdir(name)
- putFile(dest)
- putString(source, dest)
see
Methods
Sets transfer mode to ascii for transmitting text-based data.
Example:
Example:
var ftp = new FtpClient("ftp.host.dom"); ftp.login("user", "pass"); ftp.ascii();
Sets transfer mode to binary for transmitting images and other non-text files.
Example:
Example:
var ftp = new FtpClient("ftp.host.dom"); ftp.login("user", "pass"); ftp.binary();
Changes the working directory on the FTP server.
Example:
Example:
var ftp = new FtpClient("ftp.host.dom"); ftp.login("user", "pass"); // use absolute pathname ftp.cd("/home/users/fred/www"); // change to parent directory ftp.cd(".."); // use relative pathname ftp.cd("images");
parameters
String | dir | as String, the path that the remote working directory should be changed to |
Transfers a file from the FTP server to the local file system.
Example:
Example:
var ftp = new FtpClient("ftp.host.dom"); ftp.login("user", "pass"); ftp.getFile(".htaccess", "htaccess.txt");
parameters
String | source | as String, the name of the file that should be downloaded |
String | dest | as String, the name which the file should be stored under |
see
Retrieves a file from the FTP server and returns it as string.
Example:
Example:
var ftp = new FtpClient("ftp.host.dom"); ftp.login("user", "pass"); var str = ftp.getString("messages.txt");
parameters
String | source | as String, the name of the file that should be downloaded |
returns
String containing the data of the downloaded file |
see
Changes the working directory of the local machine when being connected to an FTP server.
Example:
Example:
var ftp = new FtpClient("ftp.host.dom"); ftp.login("user", "pass"); // use absolute pathname ftp.lcd("/home/users/fred/www"); // change to parent directory ftp.lcd(".."); // use relative pathname ftp.lcd("images");
parameters
String | dir | as String, the path that the local working directory should be changed to |
Logs in to the FTP server.
The function returns true if successful, false otherwise
Example:
The function returns true if successful, false otherwise
Example:
var ftp = new FtpClient("ftp.host.dom"); if (ftp.login("user", "pass")) res.write("User logged in."); else res.write("Unable to log in."); User logged in.
parameters
String | username | as String |
String | password | as String |
returns
Boolean true if the login was successful, otherwise false |
Terminates the current FTP session.
Example:
Example:
var ftp = new FtpClient("ftp.host.dom"); ftp.login("user", "pass"); ftp.putFile("htaccess.txt", ".htaccess"); ftp.logout();
Creates a new directory on the server.
The name of the directory is determined as the function's string parameter. Returns false when an error occured (e.g. due to access restrictions, directory already exists etc.), otherwise true.
Example:
The name of the directory is determined as the function's string parameter. Returns false when an error occured (e.g. due to access restrictions, directory already exists etc.), otherwise true.
Example:
var ftp = new FtpClient("ftp.host.dom"); ftp.login("user", "pass"); if (ftp.mkdir("testdir")) ftp.cd("testdir") else ftp.logout();
parameters
String | name | as String, the name of the directory to be created |
returns
Boolean true if the directory was successfully created, false if there was an error |
Transfers a file from the local file system to the remote server.
Returns true if the transmission was successful, otherwise false.
Example:
Returns true if the transmission was successful, otherwise false.
Example:
var ftp = new FtpClient("ftp.host.dom"); ftp.login("user", "pass"); if (ftp.putFile("testfile")) res.write("File transferred successfully."); else res.write("Transfer error."); File transferred successfully.
parameters
String | dest | as String, the name of the destination file to be uploaded |
returns
Boolean true if the file was successfully uploaded, false if there was an error |
Transfers text from a string to a file on the FTP server.
Example:
Example:
var ftp = new FtpClient("ftp.host.dom"); ftp.login("user", "pass"); ftp.putString("Hello, World!", "message.txt");
parameters
String | source | as String, the text content that should be uploaded |
String | dest | as String, the name of the remote destination file |
returns
Boolean true if the file was successfully uploaded, false if there was an error |