Getting session and SFTP channel in Java using JSch library

时间秒杀一切 提交于 2019-12-06 12:02:49

If you use the SFTP session frequently enough, you should not recreate it for every operation. Opening an SSH/SFTP connection is very CPU demanding, both for the client and the server. It's quite a waste to shutdown a connection, if you are going to need a new one shortly.

So consider opening a single shared session and channel at the beginning of your "application" and reuse it for all operations.


To answer your actual session: I'd introduce another class that owns both Session and ChannelSftp (with methods like getSession() and getChannel()) and return that from the factory method.


Though actually, there's getSession method in the Channel class.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!