?
在上面一個帖子里就簡單介紹了如何基于jsch實現(xiàn)ssh.
下面就簡單介紹一下如何實現(xiàn)FTP的功能通過JSCH.
public class JftpHandler extends JschHandler { private static final Logger log = LoggerFactory .getLogger(JftpHandler.class); private ChannelSftp sftp = null; public JftpHandler(String username, String host, int port, String identity) { super(username, host, port, identity); } public JftpHandler(String username, String host, int port, UserInfo userInfo) { super(username, host, port, userInfo); } @Override public void init() throws JSchException { super.init(); sftp = (ChannelSftp) session.openChannel(SFTP_PROTOCAL);//sftp sftp.connect(); log.info("Jftp connection success."); } @Override public void destory() { if (sftp != null) { sftp.quit(); sftp.disconnect(); } super.destory(); log.info("Jftp destory success."); } public void cd(String path) throws SftpException { sftp.cd(path); } public void lcd(String path) throws SftpException { sftp.lcd(path); } public String lpwd() { return sftp.lpwd(); } public String pwd() throws SftpException { return sftp.pwd(); } public void mkdir(String path) throws SftpException { sftp.mkdir(path); } public void rm(String path) throws SftpException { sftp.rm(path); } public void quit() { sftp.quit(); } public void rmdir(String path) throws SftpException { sftp.rmdir(path); } public void exit() { sftp.exit(); } public void put(String src, String dst, int mode) throws SftpException { sftp.put(src, dst, mode); } public void put(String src, String dst) throws SftpException { put(src, dst, 0); } public void put(String dst) throws SftpException { put(dst, "."); } public void get(String src, String dst) throws SftpException { sftp.get(src, dst); } public void get(String src) throws SftpException { get(src, "."); } /** * Changes the permissions of one or several remote files. * * @param permissions * @param path * @throws SftpException */ public void chmod(int permissions, String path) throws SftpException { sftp.chmod(permissions, path); } /** * @returns the protocol version number supported by this client */ public String version() { return sftp.version(); } }??上面的代碼只是對JSCH的簡單包裝,也是對JSCH的拋磚引玉。希望對大家有點用處。。。

?
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯(lián)系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
