这真的很奇怪,为什么zehon会将我的eclipse的位置和我的SFTP密码作为 FileSystemException 的一部分返回?
我检查过远程主机确实是SFTP服务器,客户端正在使用SFTP进行连接。
Zehon API here
堆栈跟踪
Reading file from C:\srcFolde\FileToBeUploaded.zip
com.zehon.exception.FileTransferException:
org.apache.commons.vfs.FileSystemException:
Unknown message with code:
"C:<location of eclipse>/<sftp password>?" does not exist
at int result = sftp.sendFile(filePath, ftpDestFolder);
代码
SFTPClient sftp = new SFTPClient(ftpServer, 22, ftpUserName, ftpPassword, true);
FileInputStream fis = null;
try {
fis = new FileInputStream(fileName);
String filePath=fileName.substring(0, fileName.length()-4) + ".zip";
String ftpDestFolder="\\sftpDestFolder";
int result = sftp.sendFile(filePath, ftpDestFolder);
Logger.debug("sftp result = " + result);
} catch (FileTransferException e) {
e.printStackTrace();
return false;
} finally {
try {
if (fis != null) {
fis.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
答案 0 :(得分:1)
您使用了错误的构造函数。来自Javadocs
http://www.zehon.com/javadocs/com/zehon/sftp/SFTPClient.html
您已经通过ftpPassword
预期privateKeyPath
。