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

PropertyReturnsDescription
idString

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.

ParameterDescription
paththe 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.

ParameterDescription
fileNamethe name to store the uploaded file as
inthe 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.

ParameterDescription
fileNamethe name to store the uploaded file as
datathe 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.

ParameterDescription
fileNamethe name of the file to download, relative to the current directory
callbackinvoked 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.

ParameterDescription
fromthe current name or path of the file
tothe new name or path for the file

deleteFile(String fileName)

Returns: void

Deletes a file on the remote server.

ParameterDescription
fileNamethe name or path of the file to delete

deleteDirectory(String path)

Returns: void

Deletes a directory on the remote server.

ParameterDescription
paththe name or path of the directory to delete

createDirectory(String path)

Returns: void

Creates a directory on the remote server.

ParameterDescription
paththe 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.

To get full access to the Kademi Hub existing customers can login here, or new customers can register here.