Ganesh - 2013-07-29

I am using jsch for sftp file transfer. When I send file using sftp command by setting the buffer size 512 (-B option ) sftp B 512 [sftp server name] and invoking put command, I can transfer files in 8.0MBPS. (The regular speed is 3.0MBPS).

When I do the same file transfer using jsch api in java, I get only 2.6MBPS. Is there any option to increase the buffer size in jsch or improve the speed of jsch?

Here is my code...

Channel channel = null;
ChannelSftp channelSftp = null;
log("preparing the host information for sftp.");
try {
JSch jsch = new JSch();

session = jsch.getSession(username, hostname, port);
session.setPassword(password);
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.connect();
System.out.println("Host connected.");
channel = session.openChannel("sftp");
channel.connect();
log("sftp channel opened and connected.");
channelSftp = (ChannelSftp) channel;
channelSftp.cd(SFTPWORKINGDIR);
File f = new File(fileName);
channelSftp.put(new FileInputStream(f), f.getName());
log("File transferred successfully to host.");

} catch (Exception ex) {
System.out.println("Exception found while transfer the response.");
ex.printStackTrace();
} finally{

channelSftp.exit();
log("sftp Channel exited.");
channel.disconnect();
log("Channel disconnected.");
session.disconnect();
log("Host Session disconnected.");

}