How to upload, download and delete a file

Uploading, downloading and deletion of files is all done through simple method calls on the FTPClient class. All methods described below are also supported in the SSLFTPClient, ProFTPClient and SSHFTPClient classes.

Uploading Files

Uploading of a file is done by the following method-call:

ftp.put(localFilePath, remoteFileName);

This method uploads the file specified by the first argument and saves it on the server with the name specified by the second argument. If the file is already present on the server then it is usually overwritten, though this depends on the server configuration.

File appending is also supported, whereby the contents of the local file are appended to the end of the remote file. Appending is done by passing true as a third parameter to the put() method:

ftp.put(localFilePath, remoteFileName, true);

Downloading Files

Downloading of a file is done by the following method-call:

ftp.get(localFilePath, remoteFileName);

This method downloads the file specified by the second argument and saves it locally with the name specified by the first argument. If the file is already present on the local storage medium then it is overwritten.

Deleting Files

A file may be deleted by calling the delete() method.

Notes:

(1) It is often useful to transfer data directly to and from memory rather than files. The topic How to transfer streams and byte-arrays explains how to do this.