com.jcraft.jsch.ChannelSftp.throwStatusError

安稳与你 提交于 2019-12-07 18:50:45

问题


Am trying to create a folder(folderName) and two files(file1.txt,file2.txt) in it.After creating folder and files, am updating its permissions.First update files' permissions then folder's.But when folder permission is getting called for update, exception is thrown.Even exception is thrown permission of the folder and files are updated properly.Please help me to find how I can prevent this Exception.

Update1 : channelSftp.chmod(511, folder);//commenting this line, works without exception but can't update permission of folder.

Update2 : channelSftp.chmod(511, folder);//this line is the problem even after removing all the lines and keeping this single line with folder creation code.Folder is created but exception comes after permission is updated.

WinSCP Screen :

Code :

        String depDir = "/BaicDirectory";
        System.out.println("Processing ........ starts");

        Session session = new FTPComponent().getSession("");
        Channel channel = null;
        ChannelSftp channelSftp = null;
        try
        {
            session.connect();
            System.out.println("session is alive:" + session.isConnected());
            channel = session.openChannel("sftp");
            channel.connect();
            channelSftp = (ChannelSftp) channel;
            InputStream ftpLogIStream = new ByteArrayInputStream("file1.txt content".getBytes());
            InputStream processLogIStream = new ByteArrayInputStream("file2.txt content".getBytes());
            channelSftp.cd(depDir);
            String folder = "folderName";
            channelSftp.mkdir(folder);
            System.out.println("Folder is created");
            channelSftp.put(ftpLogIStream, depDir + "/" + folder + "/file1.txt");
            channelSftp.put(processLogIStream, depDir + "/" + folder + "/file2.txt");
            System.out.println("Files are created");
            channelSftp.cd(depDir + "/" + folder);
            channelSftp.chmod(511, "file1.txt");
            channelSftp.chmod(511, "file2.txt");
            System.out.println("Files permissons are updated");
            channelSftp.cd(depDir);
            System.out.println("Directory to main location");
            channelSftp.chmod(511, folder);//commenting this works fine
            System.out.println("All SFTP actions are done:" + channelSftp.pwd());
        }
        catch (Exception e1)
        {
            e1.printStackTrace();         
        }
        finally
        {
            if (channelSftp != null)
            {
                channelSftp.disconnect();
            }
            if (channel != null)
            {
                channel.disconnect();
            }
            if (session != null)
            {
                System.out.println("session is alive:" + session.isConnected());
                session.disconnect();
            }
        }
        System.out.println("After all statements ........ ends");

Output :

Processing ........ starts
session is alive:true
Folder is created
Files is created
Files permissons are updated
Directory to main location
session is alive:true
Failure
        at com.jcraft.jsch.ChannelSftp.throwStatusError(Unknown Source)
        at com.jcraft.jsch.ChannelSftp._setStat(Unknown Source)
        at com.jcraft.jsch.ChannelSftp.chmod(Unknown Source)
        at com.app.sftp.CLOWriteBack.main(CLOWriteBack.java:747)
After all statements ........ ends

Update 3: WinSCP session debug 1 log

. 2015-11-23 03:06:04.555 Changing properties of "folderName" (No)
. 2015-11-23 03:06:04.555  - mode: "u+rwx-s,g+rwx-s,o+rwx-t"
> 2015-11-23 03:06:04.556 Type: SSH_FXP_LSTAT, Size: 91, Number: 10759
. 2015-11-23 03:06:04.556 Sent 95 bytes
. 2015-11-23 03:06:04.556 There are 0 bytes remaining in the send buffer
. 2015-11-23 03:06:04.556 Read 4 bytes (24 pending)
. 2015-11-23 03:06:04.556 Read 24 bytes (0 pending)
< 2015-11-23 03:06:04.556 Type: SSH_FXP_STATUS, Size: 24, Number: 10500
. 2015-11-23 03:06:04.556 Discarding reserved response
. 2015-11-23 03:06:04.556 Waiting for another 4 bytes
. 2015-11-23 03:06:04.557 Detected network event
. 2015-11-23 03:06:04.557 Received 41 bytes (0)
. 2015-11-23 03:06:04.557 Read 4 bytes (37 pending)
. 2015-11-23 03:06:04.557 Read 37 bytes (0 pending)
< 2015-11-23 03:06:04.557 Type: SSH_FXP_ATTRS, Size: 37, Number: 10759
> 2015-11-23 03:06:04.557 Type: SSH_FXP_SETSTAT, Size: 99, Number: 11017
. 2015-11-23 03:06:04.557 Sent 103 bytes
. 2015-11-23 03:06:04.557 There are 0 bytes remaining in the send buffer
. 2015-11-23 03:06:04.557 Waiting for another 4 bytes
. 2015-11-23 03:06:04.558 Detected network event
. 2015-11-23 03:06:04.558 Received 28 bytes (0)
. 2015-11-23 03:06:04.558 Read 4 bytes (24 pending)
. 2015-11-23 03:06:04.558 Read 24 bytes (0 pending)
< 2015-11-23 03:06:04.558 Type: SSH_FXP_STATUS, Size: 24, Number: 11017
< 2015-11-23 03:06:04.558 Status code: 0
. 2015-11-23 03:06:04.559 Listing directory "/BaicDirectory".
> 2015-11-23 03:06:04.559 Type: SSH_FXP_OPENDIR, Size: 80, Number: 11275
. 2015-11-23 03:06:04.559 Sent 84 bytes
. 2015-11-23 03:06:04.559 There are 0 bytes remaining in the send buffer
. 2015-11-23 03:06:04.559 Waiting for another 4 bytes
. 2015-11-23 03:06:04.560 Detected network event
. 2015-11-23 03:06:04.560 Received 17 bytes (0)
. 2015-11-23 03:06:04.560 Read 4 bytes (13 pending)
. 2015-11-23 03:06:04.560 Read 13 bytes (0 pending)
< 2015-11-23 03:06:04.560 Type: SSH_FXP_HANDLE, Size: 13, Number: 11275
> 2015-11-23 03:06:04.560 Type: SSH_FXP_READDIR, Size: 13, Number: 11532
. 2015-11-23 03:06:04.560 Sent 17 bytes
. 2015-11-23 03:06:04.560 There are 0 bytes remaining in the send buffer
. 2015-11-23 03:06:04.560 Waiting for another 4 bytes
. 2015-11-23 03:06:04.561 Detected network event
. 2015-11-23 03:06:04.561 Received 327 bytes (0)
. 2015-11-23 03:06:04.561 Read 4 bytes (323 pending)
. 2015-11-23 03:06:04.561 Read 323 bytes (0 pending)
< 2015-11-23 03:06:04.561 Type: SSH_FXP_NAME, Size: 323, Number: 11532
> 2015-11-23 03:06:04.561 Type: SSH_FXP_READDIR, Size: 13, Number: 11788
. 2015-11-23 03:06:04.561 Sent 17 bytes
. 2015-11-23 03:06:04.561 There are 0 bytes remaining in the send buffer
. 2015-11-23 03:06:04.561 Read file '.' from listing
. 2015-11-23 03:06:04.562 Read file '..' from listing
. 2015-11-23 03:06:04.562 Read file 'folderName' from listing
. 2015-11-23 03:06:04.562 Waiting for another 4 bytes
. 2015-11-23 03:06:04.562 Detected network event
. 2015-11-23 03:06:04.562 Received 32 bytes (0)
. 2015-11-23 03:06:04.562 Read 4 bytes (28 pending)
. 2015-11-23 03:06:04.562 Read 28 bytes (0 pending)
< 2015-11-23 03:06:04.562 Type: SSH_FXP_STATUS, Size: 28, Number: 11788
< 2015-11-23 03:06:04.562 Status code: 1
> 2015-11-23 03:06:04.562 Type: SSH_FXP_CLOSE, Size: 13, Number: 12036
. 2015-11-23 03:06:04.562 Sent 17 bytes
. 2015-11-23 03:06:04.562 There are 0 bytes remaining in the send buffer
. 2015-11-23 03:06:04.562 ..;d;1024;2015-11-20T13:34:34.000Z;"useracid" [24416];"useracid" [8481];rwxrwxrwx;1
. 2015-11-23 03:06:04.562 folderName;d;96;2015-11-21T08:47:52.000Z;"useracid" [24416];"useracid" [8481];rwxrwxrwx;1
. 2015-11-23 03:06:04.573 Session upkeep
. 2015-11-23 03:06:04.573 Detected network event
. 2015-11-23 03:06:04.573 Received 28 bytes (0)
. 2015-11-23 03:06:05.025 Session upkeep

来源:https://stackoverflow.com/questions/33841248/com-jcraft-jsch-channelsftp-throwstatuserror

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!