'3: Permission denied. at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2846)

We have a java code which connects to a destination server and places multiple files in the destination folder. But when it places the first file and comes back to place the second file it gives the following error.

INFO: Next authentication method: keyboard-interactive INFO: Authentication succeeded (keyboard-interactive). 3: Permission denied. at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2846) at com.jcraft.jsch.ChannelSftp._put(ChannelSftp.java:594) at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:475) at com.jcraft.jsch.ChannelSftp.put(ChannelSftp.java:365) at TravelFTPUpload.main(TravelFTPUpload.java:103) INFO: Disconnecting from 12.10.219.115 port 22 INFO: Caught an exception, leaving main loop due to Socket closed

Java code snippet:

for (int j = 0; j < listFiles.length; j++) 
{
    fN = listFiles[j].getAbsolutePath();
    destFn = listFiles[j].getName();
    fileNameList.append(destFn+"<br />");

    // Ex:GS2-20141128
    sftpChannel.put(fN, destFn);

}

Can someone please help me with this error. Note: The code works fine while connecting to a different destination folder.



Solution 1:[1]

I had a similar problem and it was due an non existent folder. Did you check if the folder exists? Is it in the correct path?

Solution 2:[2]

Be sure to indicate the working directory in the channel

Use channel.cd("/path_directory")

ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
channel.connect();
channel.cd("/path_directory");

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Community
Solution 2 Ronald Coarite