码迷,mamicode.com
首页 > 编程语言 > 详细

SFTPTooL.java 1

时间:2016-01-12 11:42:46      阅读:274      评论:0      收藏:0      [点我收藏+]

标签:

 

两个工具类依赖的jar包:

技术分享

 

 

FTPTool.java

public static void main(String[] args) throws Exception{
        FTPTooL ftpTool = new FTPTooL();
        FTPClient ftpClient  = null;
        InputStream stream = null;
        stream = StreamTool.getStreamFromString(StreamTool.streamStr);
        
        try{
            String host = "10.16.55.21";//ip
            int port = 21;                //port
            String username = "zssys";//user
            String password = "zssys";//password
            
            ftpClient = ftpTool.createFtpClient(host, port, username, password,null,null);
            ftpTool.mkdir    ("/home/zstest/dvlp/pic_test/underwrt_pic/test/", "123/456/789", ftpClient);//建目录
            ftpTool.upload    ("/home/zstest/dvlp/pic_test/underwrt_pic/test/", "D:/temp/","HousingEstateManagerment.rar", ftpClient);//上传
            ftpTool.upload    ("/home/zstest/dvlp/pic_test/underwrt_pic/test/", stream,"ddd.PNG", ftpClient);//上传
            ftpTool.download    ("/home/zstest/dvlp/pic_test/underwrt_pic/test/", "ddd.PNG", "D:/temp/haha/","download.PNG", ftpClient);//下载
            ftpTool.delete    ("/home/zstest/dvlp/pic_test/underwrt_pic/test/", "delete.txt", ftpClient);//删除
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            ftpTool.disconnect(ftpClient);
        }
    }

 

 

 

 

SFTPTool.java

public static void main(String[] args) throws Exception{
        SFTPTooL sfTool = new SFTPTooL();
        Session session = null;
        ChannelSftp channel = null;
        InputStream stream = null;
        stream = StreamTool.getStreamFromString(StreamTool.streamStr);
        
        try{
            String host = "10.15.22.120";//ip
            int port = 22;                //port
            String username = "weblogic";//user
            String password = "weblogic";//password
            session = sfTool.getSession(host, port, username, password);
            channel = sfTool.getConnect(session);
            sfTool.mkdir    ("/data/temp/test/", "123/888/789", channel);//建目录
            sfTool.upload    ("/data/temp/test/", "D:/temp/","HousingEstateManagerment.rar", channel);//上传
            sfTool.upload    ("/data/temp/test/", stream,"ddd.PNG", channel);//上传
            sfTool.download    ("/data/temp/test/", "download.txt", "D:/temp/haha/","download.txt", channel);//下载
            sfTool.delete    ("/data/temp/test/", "delete.txt", channel);//删除
        }catch(Exception e){
            e.printStackTrace();
        }finally{
            sfTool.disconnect(channel,session);
        }
    }

 

SFTPTooL.java 1

标签:

原文地址:http://www.cnblogs.com/bobo1713930654/p/5123477.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!