Using JSch (a java ssh lib, used by Ant for example), you could do something like that :
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();
}
}
}
Here is another link using JSch to do SFTP.
You can use JSch directly this way, or through Commons VFS, but then you'll have to have both commons vfs jar and jsch jar.