Java 将文件上载到sftp(私钥验证)时JSch出错
我正在尝试在私钥身份验证之后使用JSch libs将文件上载到sftp服务器。但是put、mkdir等操作会抛出失败消息。我尝试了几种方法,当然这在JSch中看起来是个问题,有人遇到过这个问题吗 同样的代码(mkdir,put)非常适合非私钥(用户名/密码)身份验证。你能帮帮我吗。sftpChannel.ls也在使用私钥方法 我的代码:Java 将文件上载到sftp(私钥验证)时JSch出错,java,ftp,sftp,jsch,Java,Ftp,Sftp,Jsch,我正在尝试在私钥身份验证之后使用JSch libs将文件上载到sftp服务器。但是put、mkdir等操作会抛出失败消息。我尝试了几种方法,当然这在JSch中看起来是个问题,有人遇到过这个问题吗 同样的代码(mkdir,put)非常适合非私钥(用户名/密码)身份验证。你能帮帮我吗。sftpChannel.ls也在使用私钥方法 我的代码: JSch jsch = new JSch(); Session session = null; if (privateKey != n
JSch jsch = new JSch();
Session session = null;
if (privateKey != null||"".equals(privateKey)) {
jsch.addIdentity(privateKey);
}
session = jsch.getSession(userName, hostAddress, port);
session.setConfig("StrictHostKeyChecking", "no");
if(password!=null||"".equals(password)){
session.setPassword(password);
}
session.connect();
Channel channel = null;
if (sftp) {
channel = session.openChannel("sftp");
} else {
channel = session.openChannel("ftp");
}
session.setServerAliveInterval(92000);
channel.connect();
ChannelSftp sftpChannel = (ChannelSftp) channel;
// sftpChannel.put(new FileInputStream(new File(path)), remotePath );
// final Vector files = sftpChannel.ls(".");
// for (Object obj : files) {
// System.out.println("f:"+obj);
// }
sftpChannel.exit();
session.disconnect();
问题解决了。远程服务器没有足够的空间在该用户帐户中创建新文件。我清洁了服务器,但不是所有东西都正常工作-Raghu你能添加你的“解决方案”作为答案(而不是评论),然后接受它,这样它就会被视为解决了吗?谢谢用户233640:Paŭlo Ebermann是对的。请你自己发布一个问题的答案,然后接受这个答案,这样我们就可以结束这个问题了?此外,如果前面的问题解决了您的问题,您需要接受这些问题的答案。
Exception in thread "main" 4: Failure
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2297)
at com.jcraft.jsch.ChannelSftp.mkdir(ChannelSftp.java:1708)
at zz.beans.RemoteExportBean.exportToFTP(RemoteExportBean.java:52)
at zz.beans.RemoteExportBean.main(RemoteExportBean.java:67)
Exception in thread "main" 4: Failure
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2297)
at com.jcraft.jsch.ChannelSftp.checkStatus(ChannelSftp.java:1946)
at com.jcraft.jsch.ChannelSftp._put(ChannelSftp.java:566)
at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:438)
at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:405)
at zz.beans.RemoteExportBean.exportToFTP(RemoteExportBean.java:52)
at zz.beans.RemoteExportBean.main(RemoteExportBean.java:66)