jsch文件复制(拷贝)

 

public void copyFile(Session session, String sourceFile, String destinationFile) {
    ChannelExec channel = (ChannelExec) session.openChannel("exec");
    channel.setCommand("cp " + sourceFile + " " + destinationFile);
    channel.connect();
    while(channel.isConnected()) {
        Thread.sleep(20);
    }
    int status = channel.getExitStatus();
    if(status != 0)
      throw new CopyException("copy failed, exit status is " + status);
}

 

 

How can I copy a file on the server using JSch's SCP support?

 

posted @ 2021-09-10 19:43  牧之丨  阅读(356)  评论(0编辑  收藏  举报