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");
sftpChannel.exit();
session.disconnect();
} catch (JSchException e) {
e.printStackTrace();
} catch (SftpException e) {
e.printStackTrace();
}
}
我不想要这个sftpChannel.get(“remotefile.txt”,“localfile.txt”);
我只是想创建两个方法
1)将文件从远程位置复制到本地系统
2)在sftp连接中删除复制的文件
谁能帮忙..
解决方法:
执行远程文件的副本,然后将其删除
ChannelSftp.get("remotefile.txt", "localfile.txt");
ChannelSftp.rm("remotefile.txt")