0
我已经搜索了很多,但无法获得解决方案。我需要从本地Windows机器使用Java程序复制到远程Windows机器的文件。我试图与JSch,使用java将文件从本地窗口机器复制到远程Windows机器
JSch jsch = new JSch();
Session session = null;
session = jsch.getSession("username","hostname",22);
session.setPassword("password");
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
ChannelSftp channel = null;
channel = (ChannelSftp)session.openChannel("sftp");
channel.connect();
File localFile = new File("filePath");
//If you want you can change the directory using the following line.
channel.cd("E:/xxx");
channel.put(new FileInputStream(localFile),localFile.getName());
channel.disconnect();
session.disconnect();
在执行上面的代码,我面临下面的错误,
Exception in thread "main" 2: No such file
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2846)
at com.jcraft.jsch.ChannelSftp._realpath(ChannelSftp.java:2340)
at com.jcraft.jsch.ChannelSftp.cd(ChannelSftp.java:342)
我已经cygwin的安装在远程的Windows机器。看来Jsch无法找到Windows路径。将文件从Windows机器复制到Linux机器时,相同的代码正常工作。
请给我一个解决上述问题的方法,或者是否有任何其他选项可以在java中实现?谢谢
谢谢。它工作完美.. – Jugi