Error While Uploading a file using put

Anonymous
2011-07-25
2013-05-28

  • Anonymous
    2011-07-25

    Hi

    I'm trying to upload a file to a sftp server using privateKey file. But while uploading I'm getting following error and the same connection is working for sftpChannel.ls("."). Please let me know where I'm doing wrong.

    debug:
    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:408)
    at ambivo.beans.RemoteExportBean.exportToFTP(RemoteExportBean.java:58)
    at ambivo.beans.RemoteExportBean.main(RemoteExportBean.java:72)

     private void exportToFTP(String path, String remotePath, String hostAddress, int port, 
                String userName, String password,
                String privateKey, boolean sftp) throws Exception {
            JSch jsch = new JSch();
            Session session = null;
            if (privateKey != null||"".equals(privateKey)) {
                final byte[] prvkey = readMyPrivateKeyFromFile(privateKey); // Private key must be byte array
                final byte[] emptyPassPhrase = new byte[0]; // Empty passphrase for now, get real passphrase from MyUserInfo
                jsch.addIdentity(
                        userName,
                        prvkey, // byte[] privateKey 
                        null, // byte[] publicKey
                        emptyPassPhrase // byte[] passPhrase
                        );
            }
            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(2000);
            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();
        }
    
     

  • Anonymous
    2011-07-26

    Got the fix, it's just because of the server is out of space , took very long time to figure this out