How to use SFTP (with client validation - password authentication)

The topic How to use SFTP (introduction) describes the SFTP features of SSHFTPClient. This topic demonstrates the use of SFTP with the simplest form of client validation - password authentication.

You should ensure that the server's public keys are loaded by the client as described in How to use SFTP (with server validation - known hosts)), or you may want to switch off server validation to get started.

Client authentication can be either by password, by public/private keys, or by keyboard-interactive authentication.

Password authentication is generally the easiest to try first, although some SFTP servers are set up to disallow password authentication, in which case the connection attempt will fail unless password authentication is enabled in the server configuration file.To use password authentication, call the setAuthentication method before calling connect, supplying the username and password:

ftp.setAuthentication(username, password);
ftp.connect();

The user name and password should be that of the SSH user that the client is logging in as.

Note that some SFTP servers are set up to disallow password authentication, in which case the connection attempt will fail unless password authentication is enabled in the server configuration file.

Public key authentication is discussed in How to use SFTP (with client validation - public key authentication).

Keyboard-interactive authentication is discussed in How to use SFTP (with client validation - keyboard-interactive authentication).