首页 > 编程语言 > 详细

sftp多线程下载

时间:2019-02-13 00:52:13      阅读:144      评论:0      收藏:0      [点我收藏+]

标签:pen   open   .exe   check   pic   incr   rgs   sftp   execute   

 //上传文件测试
    public static void main(String[] args) throws SftpException, IOException {
        ExecutorService exec = Executors.newFixedThreadPool(10);
        for (int i = 0; i <10 ; i++) {
            exec.execute(new Runnable() {
                public void run() {

                    try {
                        JSch jsch = new JSch();

                        Session session = jsch.getSession("root",  "192.168.60.128", 22);

                        session.setPassword("lxz499929793");

                        Properties config = new Properties();
                        config.put("StrictHostKeyChecking", "no");

                        session.setConfig(config);
                        session.connect();

                        Channel channel = session.openChannel("sftp");
                        channel.connect();

                        ChannelSftp sftp = (ChannelSftp) channel;
                        sftp.cd("/root/pic");
                        atomicInteger.incrementAndGet();
                        sftp.get( "banner4.jpg", "D:\\aaadown\\xxxxx"+atomicInteger+".jpg");
                        sftp.disconnect();
                        session.disconnect();
                    } catch (JSchException e) {
                        e.printStackTrace();
                    } catch (SftpException e) {
                        e.printStackTrace();
                    }
            }
            });

        }
        while (true){
            if(atomicInteger.get()==10){

                exec.shutdown();
                System.out.println("下载好了");
                break;
            }
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }

 

sftp多线程下载

标签:pen   open   .exe   check   pic   incr   rgs   sftp   execute   

原文:https://www.cnblogs.com/georgeJavaEE/p/10367644.html

(0)
(0)
   
举报
评论 一句话评论(0
0条  
登录后才能评论!
© 2014 bubuko.com 版权所有 鲁ICP备09046678号-4
打开技术之扣,分享程序人生!
             

鲁公网安备 37021202000002号