Back

Directory Methods

 ftp.GetCurrentDirectory();

Returns: The current working directory


 ftp.ChangeWorkingDirectory(path);

Changes the current working directory to 'path'. This can be relative to current working directory, or absolute from the FTP root directory.

Returns: boolean true or false
Use ftp.GetError() for error handling.


 ftp.GetDirectoryList(path);

This method returns a Multi-Dimensional Array Object, each dimension contains the following keys: name, type, size, user, group, timestamp, datetime.

Size is in bytes. Type will be either 'File' or 'Directory'. Timestamp and Datetime have the same value, just formatted differently.

Example - Directory List

var list = ftp.GetDirectoryList('');
if (ftp.GetError()) { app.ShowPopup(ftp.GetError()); }
if (list) {
  var len = list.length;
  var s = '';
  for(var i = 0; i < len; i++ ) 
  {
       var file = list[i];
    s += "Name: " + file.name + "\nType: " + file.type + "\nSize: " + file.size + " bytes\n" + file.timestamp + "\n\n";
     }
     app.Alert(s);
}
  Copy  

Returns: Multi-Dimensional Array Object or Boolean false on Error.
Use ftp.GetError() for error handling.


 ftp.CreateDirectory(path);

This will create a new directory 'path'. If relative it will create it relative to CurrentWorkingDirectory. Absolute paths start at the FTP root directory.

Returns: boolean true or false
Use ftp.GetError() for error handling.


 ftp.RemoveDirectory(path);

This will remove the directory 'path'. It can be relative or absolute. The directory must be empty or this will fail.

Returns: boolean true or false
Use ftp.GetError() for error handling.


 ftp.DirectoryExists(directory);

This will check if a 'directory' exists on the server. The path can be relative to CurrentWorkingDirectory or absolute from the FTP root. Use ftp.FileExists for checking if a file exists.

Returns: boolean true or false
Use ftp.GetError() for error handling.


 ftp.SetOnStatus(callback);

This allows a callback to process the status of uploading/downloading directories and force deleting a directory using the next three methods (ftp.UploadDirectory, ftp.DownloadDirectory, and ftp.ForceDeleteDirectory). Be advised, this can be called multiple times, rapidly, as the server handles the requests. Be sure to add/append the responses to keep an accurate record. This should be set before calling any of the following methods.

Returns: String containing status messages to your callback function.


 ftp.DownloadDirectory(remote, local, mode);

This will download 'remote' directory, recursively (all included sub-directories and files) to 'local' storage. 'remote' can be relative to CurrentWorkingDirectory or absolute to FTP root. 'local' must be an absolute path (Example: '/sdcard'). Mode accepts two options, 'ASCII' and 'BINARY'. Defaults to 'BINARY'.

Use ftp.SetOnStatus to set a callback to process transfer status messages.

Returns: boolean true or false
Use ftp.GetError() for error handling.

Example - Download Directory

ftp.SetOnStatus ( status_callback );
ftp.DownloadDirectory('/images', '/sdcard', 'BINARY');
  Copy  


 ftp.UploadDirectory(local, remote, mode);

This will upload 'local' directory, recursively (all included sub-directories and files) to 'remote' server. 'remote' can be either relative to CurrentWorkingDirectory or an absolute path from FTP root. Mode accepts two options, 'ASCII' and 'BINARY'. Defaults to 'BINARY'.

Use ftp.SetOnStatus to set a callback to process transfer status messages.

Returns: boolean true or false
Use ftp.GetError() for error handling.


 ftp.ForceDeleteDirectory(directory);

This will force delete 'directory', including all sub-directories and files.

Use ftp.SetOnStatus to set a callback to process directory delete status messages.

Returns: boolean true or false
Use ftp.GetError() for error handling.