将文件上载到sftp时,JSch中的失败错误(私钥验证)

Rag*_*ndy 6 java ftp sftp jsch

我试图在私钥认证后使用JSch库将文件上传到sftp服务器.但是,put,mkdir等动作正在抛出失败的消息.我尝试了几种方法,确定它看起来像JSch中的一个问题,是否有人遇到过这个问题?

相同的代码(mkdir,put)适用于非私钥(用户名/密码)身份验证.请你帮助我好吗.sftpChannel.ls也在使用私钥方法.

我的代码:

    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();
Run Code Online (Sandbox Code Playgroud)
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)
Run Code Online (Sandbox Code Playgroud)
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)
Run Code Online (Sandbox Code Playgroud)