Editar: Voy a mantener mi respuesta anterior, como JSch todavía se utiliza en muchos lugares, pero si necesita una biblioteca mejor documentada, puede utilizar sshj. Un ejemplo de cómo utilizarlo para hacer SFTP es:
SSHClient ssh = new SSHClient();
ssh.loadKnownHosts();
ssh.connect("host");
try {
ssh.authPassword("username", "password");
SFTPClient sftp = ssh.newSFTPClient();
try {
sftp.put(new FileSystemFile("/path/of/local/file"), "/path/of/ftp/file");
} finally {
sftp.close();
}
} finally {
ssh.disconnect();
}
Usando JSch (un lib SSH Java, utilizado por la hormiga por ejemplo), se puede hacer algo así:
Session session = null;
Channel channel = null;
try {
JSch ssh = new JSch();
ssh.setKnownHosts("/path/of/known_hosts/file");
session = ssh.getSession("username", "host", 22);
session.setPassword("password");
session.connect();
channel = session.openChannel("sftp");
channel.connect();
ChannelSftp sftp = (ChannelSftp) channel;
sftp.put("/path/of/local/file", "/path/of/ftp/file");
} catch (JSchException e) {
e.printStackTrace();
} catch (SftpException e) {
e.printStackTrace();
} finally {
if (channel != null) {
channel.disconnect();
}
if (session != null) {
session.disconnect();
}
}
Aquí está another link usando JSch para hacer SFTP.
Puede usar JSch directamente de esta manera, o por medio de Commons VFS, pero luego tendrá que tener los dos jar comunes, vfs jar y jsch.
ftp over a ssh tunnel? –
http://en.wikipedia.org/wiki/SSH_File_Transfer_Protocol –
Utilice el término "SFTP" si eso es lo que quiere decir. Entre FTP, SFTP/SSH, FTPS y túnel FTP regular sobre SSH, los acrónimos se vuelven ambiguos. – prestomation