我正在尝试使用JSch从远程计算机传输文件,每当我执行代码时,我得到异常“com.jcraft.jsch.JSchException:连接被外部主机关闭”。我的代码在下面给出,它甚至不打印“会话建立”,所以我的问题是在seeion.connetct(); 请帮忙。
String SFTPHOST ="hostname";
int SFTPPORT = 23;
String SFTPUSER = "user";
String SFTPPASS = "passwrd";
String source ="source file";
Stirng dest ="destination";
Session session = null;
Channel channel = null;
ChannelSftp channelSftp = null;
try{
JSch jsch = new JSch();
session = jsch.getSession(SFTPUSER,SFTPHOST,SFTPPORT);
session.setPassword(SFTPPASS);
session.connect();
System.out.println("session connected...");
channel = session.openChannel("sftp");
channel.connect();
System.out.println("channel connected...");
channelSftp = (ChannelSftp)channel;
channelSftp.get(source,dest);
System.out.println("Transfer completed");
}catch(Exception ex){
ex.printStackTrace();
}