An open connection to a remote FTP or SFTP server, returned by FtpManager.openFtp or FtpManager.openSFtp for an app script to transfer files with. Wraps either a plain FTP/FTPS client or an SFTP channel behind a common set of operations for navigating directories, listing, uploading, downloading, renaming and deleting. The underlying connection is tracked by the owning FtpManager and is automatically force-closed after a maximum duration, but a script should call close explicitly once it is finished.
Properties
| Property | Returns | Description |
|---|---|---|
| id | String |
Methods
changeDir(String path) · uploadFile(String fileName, InputStream in) · uploadFile(String fileName, String data) · listFiles() · downloadFile(String fileName, Consumer<InputStream> callback) · currentDir() · rename(String from, String to) · deleteFile(String fileName) · deleteDirectory(String path) · createDirectory(String path) · close()
changeDir(String path)
Returns: void
Changes the current working directory on the remote server for this session. Subsequent calls that operate on relative paths, such as listFiles, act within the new directory.
| Parameter | Description |
|---|---|
path | the directory to change to, absolute or relative to the current directory |
uploadFile(String fileName, InputStream in)
Returns: void
Uploads a file to the current working directory on the remote server, reading its content from the given stream.
| Parameter | Description |
|---|---|
fileName | the name to store the uploaded file as |
in | the stream to read the file content from; consumed but not closed by this method |
uploadFile(String fileName, String data)
Returns: void
Uploads a file to the current working directory on the remote server, using the given string as its content.
| Parameter | Description |
|---|---|
fileName | the name to store the uploaded file as |
data | the text content to write to the file, encoded using the platform default charset |
listFiles()
Returns: List<FileSpec>
Lists the files and subdirectories in the current working directory on the remote server.
downloadFile(String fileName, Consumer<InputStream> callback)
Returns: void
Downloads a file from the current working directory on the remote server and passes its content to the given callback as a stream. The callback receives null if the download was not successful.
| Parameter | Description |
|---|---|
fileName | the name of the file to download, relative to the current directory |
callback | invoked with a stream over the downloaded content, or null if the download failed |
currentDir()
Returns: String
Returns the pathname of the current working directory on the remote server.
rename(String from, String to)
Returns: void
Renames or moves a file on the remote server.
| Parameter | Description |
|---|---|
from | the current name or path of the file |
to | the new name or path for the file |
deleteFile(String fileName)
Returns: void
Deletes a file on the remote server.
| Parameter | Description |
|---|---|
fileName | the name or path of the file to delete |
deleteDirectory(String path)
Returns: void
Deletes a directory on the remote server.
| Parameter | Description |
|---|---|
path | the name or path of the directory to delete |
createDirectory(String path)
Returns: void
Creates a directory on the remote server.
| Parameter | Description |
|---|---|
path | the name or path of the directory to create |
close()
Returns: void
Closes the underlying FTP or SFTP connection and stops this session from being tracked by the owning FtpManager. A script should call this once it has finished transferring files.