2

I'm running into this problem where sftpChannel.rename fail with not very helpful error and I can't figure out the reason. File does not exist in destination. Permission are fine because the mv command works. I'll list the permission of both file and folder. Does anybody has any idea? I don't have to use the directory, but it's frustrating not knowing why it is failing.

This is a piece of test code. RemoteFile is just a wrapper around the sftpChannel so I can check if file/dir exists and delete file or create dir when necessary:

 String file = "/u01/apps/tpms/applstg2/ken_test/TestFile";
 String destDir = "/usr/local/jboss/server/applstg2/backup/"; // Caused by: 4: Failure
 //String destDir = "/u01/apps/tpms/applstg2/ken_test/backup/"; // Success
 RemoteFile remoteFile = new RemoteFile(file, ssh.openSftpChannel());
 remoteFile.rename(destDir + "/TestFile");

This is the line where it failed:

sftpChannel.rename(file, newName);

This is the trace (I removed all the JUnit and sun.reflect traces):

Error renaming file /u01/apps/tpms/applstg2/ken_test/TestFile to /usr/local/jboss/server/applstg2/backup//TestFile
at com.framework.remote.RemoteFile.rename(RemoteFile.java:82)
at com.framework.remote.RemoteFileTest.renameFile(RemoteFileTest.java:56)
Caused by: 4: Failure
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2846)
at com.jcraft.jsch.ChannelSftp.rename(ChannelSftp.java:1923)
at com.framework.remote.RemoteFile.rename(RemoteFile.java:79)

Permissions:

drwxrwxr-x  2 applstg2 applstg2   4096 May  2 22:09 ken_test
-rw-rw-r-- 1 applstg2 applstg2 61595086 May  1 18:05 TestFile
drwxrwxr-x  2 applstg2 applstg2 4096 May  2 21:57 backup

1 Answer 1

5

I bet your source and destination paths are on different volumes, and that the Sftp server can't deal with moving the file across volumes because that isn't a simple rename.

Do a df -lk or otherwise figure out what the mountpoints are above each of your two locations. This is the only thing I can think that would explain this, and looking at how different the top levels of your two paths are, it seems quite possible.

If this is the case, I'd think you'd want to use a remote command execution to do this rename/move...ssh [email protected] mv xxx yyy. I'm not sure if this is what you mean by 'mv', or if you're doing that locally on the server right now.

1
  • Yeah, df -lk shows one Mounted on /u01 and another mounted on /usr, and some other mount points. And I was running mv in the Terminal on that server. Thanks, I guess I'll move the methods to exec channel instead. Thanks a tons! May 3, 2019 at 4:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.