Default properties and methods of the FTP prototype.
To use this optional module, its repository needs to be added to the application, for example by calling app.addRepository('modules/helma/Ftp.js')
To use this optional module, its repository needs to be added to the application, for example by calling app.addRepository('modules/helma/Ftp.js')
Constructor for FTP client objects, to send and receive files from an FTP server.
var ftp = new helma.Ftp("ftp.mydomain.com");
parameters
String | server | as String, the address of the FTP Server to connect to |
methods
- setReadTimeout(timeout)
- setTimeout(timeout)
- login(username, password)
- binary()
- ascii()
- active()
- passive()
- pwd()
- dir(path)
- mkdir(dir)
- rmdir(dir)
- cd(dir)
- lcd(dir)
- putFile(localFile, remoteFile)
- putString(str, remoteFile, charset)
- putBytes(bytes, remoteFile)
- getFile(remoteFile, localFile)
- getString(remoteFile)
- deleteFile(remoteFile)
- renameFile(from, to)
- logout()
Methods
Set the default timeout in milliseconds to use when opening a socket.
parameters
timeout |
Sets the timeout in milliseconds to use when reading from the data connection.
parameters
timeout |
Logs in to the FTP server.
parameters
String | username | as String |
String | password | as String |
returns
Boolean true if the login was successful, otherwise false |
Sets transfer mode to binary for transmitting images and other non-text files.
ftp.binary();
Returns the path of the current working directory.
var remotepath = ftp.pwd();
returns
String containing the current working directory path |
Returns a listing of the files contained in a directory on the FTP server.
Lists the files contained in the current working directory or, if an alternative path is specified, the files contained in the specified directory.
Lists the files contained in the current working directory or, if an alternative path is specified, the files contained in the specified directory.
var filelist = ftp.dir();
parameters
String | path | as String, optional alternative directory |
returns
Array containing the list of files in that directory |
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.
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.
parameters
String | dir | 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 |
Deletes a directory on the FTP server.
parameters
String | dir | as String, the name of the directory to be deleted |
returns
Boolean true if the deletion was successful, false otherwise |
Changes the working directory on the FTP server.
ftp.cd("/home/users/fred/www"); // use absolute pathname
ftp.cd(".."); // change to parent directory
ftp.cd("images"); // use relative pathname
parameters
String | dir | as String, the path that the remote working directory should be changed to |
Changes the working directory of the local machine when being connected to an FTP server.
ftp.lcd("/home/users/fred/www"); // use absolute pathname
ftp.lcd(".."); // change to parent directory
ftp.lcd("images"); // use relative pathname
parameters
String | dir | as String, the path that the local working directory should be changed to |
Transfers a file from the local file system to the remote server.
Returns true if the transmission was successful, otherwise false.
Returns true if the transmission was successful, otherwise false.
parameters
String | localFile | as String, the name of the file to be uploaded |
String | remoteFile | as String, the name of the remote destination file |
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.
ftp.putString("Hello, World!", "message.txt");
parameters
String | str | as String, the text content that should be uploaded |
String | remoteFile | as String, the name of the remote destination file |
String | charset | as String, optional |
returns
Boolean true if the file was successfully uploaded, false if there was an error |
Transfers a byte array to a file on the FTP server.
parameters
Array | bytes | The byte array that should be uploaded |
String | remoteFile | The name of the remote destination file |
returns
Boolean True if the file was successfully uploaded, false if there was an error |
Transfers a file from the FTP server to the local file system.
ftp.getFile(".htaccess", "htaccess.txt");
parameters
String | remoteFile | as String, the name of the file that should be downloaded |
String | localFile | as String, the name which the file should be stored under |
see
Retrieves a file from the FTP server and returns it as string.
var str = ftp.getString("messages.txt");
parameters
String | remoteFile | as String, the name of the file that should be downloaded |
returns
String containing the data of the downloaded file |
see
Deletes a file on the FTP server.
var str = ftp.deleteFile("messages.txt");
parameters
String | remoteFile | as String, the name of the file to be deleted |
returns
Boolean true if the deletion was successful, false otherwise |
Renames a file on the FTP server.
var success = ftp.renameFile("messages.tmp", "messages.txt");
parameters
String | from | the name of the original file |
String | to | the new name the original file should get |
returns
Boolean true if renaming the remote file was successful, false otherwise |
Terminates the current FTP session.