I use JSCH to download sftp files ever. In this current state, each thread opens and closes the connection when necessary.
If you can use the connection pool with AOX to avoid the overhead caused by a large number of open and close connections?
Here is an example of a function called from within a thread
public static void file_upload(String filename) throws IOException { JSch jsch = new JSch(); Session session = null; try { session = jsch.getSession("user", "server_name", 22); session.setConfig("StrictHostKeyChecking", "no"); session.setPassword("super_secre_password"); session.connect(); Channel channel = session.openChannel("sftp"); channel.connect(); ChannelSftp sftpChannel = (ChannelSftp) channel; FileInputStream inputSrr = new FileInputStream(filename); try { sftpChannel.put(inputSrr, "/var/temp/"+filename); } catch (SftpException e) { e.printStackTrace(); } finally { if (inputSrr != null) { inputSrr.close(); } } sftpChannel.exit(); session.disconnect(); } catch (JSchException e) { e.printStackTrace(); } catch (SftpException e) { e.printStackTrace(); } }
source share