日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

jsch 深入淺出(二)

系統(tǒng) 1819 0

?

在上面一個帖子里就簡單介紹了如何基于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的拋磚引玉。希望對大家有點用處。。。

?

jsch 深入淺出(二)


更多文章、技術交流、商務合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

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

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!??!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 平度市| 从化市| 河津市| 永和县| 新宁县| 锦屏县| 丹巴县| 广东省| 广灵县| 高陵县| 陇川县| 胶南市| 夏河县| 广南县| 凉城县| 德阳市| 敦煌市| 霍邱县| 中山市| 满城县| 龙川县| 棋牌| 离岛区| 云和县| 沈丘县| 连平县| 武定县| 杂多县| 太谷县| 突泉县| 九龙城区| 宜君县| 日照市| 公安县| 河曲县| 和平区| 郸城县| 海淀区| 仙游县| 清河县| 莲花县|