开发者

Copying a file in sftp with jsch library

开发者 https://www.devze.com 2023-02-07 00:51 出处:网络
import com.jcraft.jsch.*; public class App { public static void main(String args[]) { JSch jsch = new JSch();
import com.jcraft.jsch.*;

public class App {
public static void main(String args[]) {
    JSch jsch = new JSch();
    Session session = null;
    try {
        session = jsch.getSession("Username", "Host", PORT NO);
        session.setConfig("StrictHostKeyChecking", "no");
        session.setPassword("Password");
        session.connect();

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

        sftpChannel.get("remotefile.txt", "localfile.txt");
     开发者_StackOverflow社区   sftpChannel.exit();
        session.disconnect();
    } catch (JSchException e) {
        e.printStackTrace(); 
    } catch (SftpException e) {
        e.printStackTrace();
    }
}

I dont want this sftpChannel.get("remotefile.txt", "localfile.txt");

I just want to create two methods 1)to copy the file from remote location to local system 2)to remove the copied file in an sftp connection

Can anyone help..


Do a copy of the remote file and then delete it

ChannelSftp.get("remotefile.txt", "localfile.txt");
ChannelSftp.rm("remotefile.txt")
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号