I am using the JSch API for Java for SFTP connections. Sometimes t开发者_如何转开发he server may be down for a second or the connection may be busy. In these cases I would need to re-connect to the server three times at least before I decide the connection has failed.
Does JSch provide any configuration option to do this automatically?
JSch has no such configuration option, but you can simply do this yourself.
Session s = new Session(...);
for(int i = 0; i < MAX_TRIES; i++) {
try {
s.connect();
break;
}
catch(JSchException ex) {
if(i == MAX_TRIES - 1)
throw ex;
continue;
}
}
After executing this block, either the session is connected or a JSchException is thrown.
精彩评论