Reputation: 1
I am trying to upload a file to a server (with java) where I have an acount and the SFTP connection stopped working (for a timeout problem I guess). I want to know is there a way to reset this connection and get it working. This is the function:
public static void upload(File file, boolean retry) {
try
{
System.out.println("Uplodaing file " + file.getName());
JSch jsch = new JSch();
Session session = jsch.getSession("****", "*****", 22);
session.setPassword("*****");
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
session.setTimeout(5);
System.out.println("Establishing connection");
session.connect(10);
Channel channel = session.openChannel("sftp");
channel.connect();
ChannelSftp sftpChannel = (ChannelSftp) channel;
if (!retry)
sftpChannel.put(file.getAbsolutePath(), file.getName(),new SystemOutProgressMonitor(), ChannelSftp.OVERWRITE);
else
sftpChannel.put(file.getAbsolutePath(), file.getName(),new SystemOutProgressMonitor(), ChannelSftp.RESUME);
channel.disconnect();
session.disconnect();
}
catch (Exception e)
{
e.printStackTrace();
upload(file, false);
}
}
Upvotes: 0
Views: 8858
Reputation: 782
I know this question is quite old but in case anyone stumbles over it (as I did): The problem is the connection timeout, which should be in milliseconds. In case OP intended 10 seconds, it should be 10000 here. 10 milliseconds simply isn't enough.
Upvotes: 1