I am trying to fetch a file from Linux/Windows to a windows system, and I have written a code for this. But it seems there is some problem, either with the code or Jsch itself.
public static void main(String[] args) {
String host = "<IP>";
int port = Integer.parseInt("22");
String userName = "<USERNAME>";
String password = "<PASSWORD>";
ChannelSftp sftpChannel = null;
try {
JSch jsch = new JSch();
Session session = jsch.getSession(userName, host, port);
session.setConfig("StrictHostKeyChecking", "no");
session.setPassword(password);
session.connect();
// open an SFTP channel
Channel channel = session.openChannel("sftp");
channel.connect();
sftpChannel = (ChannelSftp) channel;
File headerFolder = new File("/home/userName/testFiles");
if (!headerFolder.exists()) {
headerFolder.mkdirs();
}
sftpChannel.get("/d/myfile.txt","/home/username/aFolder"); //windows to linux
} catch (JSchException e) {
//LOGGER.error(e.getMessage(), e);
e.printStackTrace();
} catch (SftpException e) {
//LOGGER.error(e.getMessage(), e);
e.printStackTrace();
}
}
2: The file does not exist.
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2846)
at com.jcraft.jsch.ChannelSftp._stat(ChannelSftp.java:2198)
at com.jcraft.jsch.ChannelSftp._stat(ChannelSftp.java:2215)
at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:913)
at com.jcraft.jsch.ChannelSftp.get(ChannelSftp.java:873)
Please Help me out with this!
Aucun commentaire:
Enregistrer un commentaire