Reputation: 235
I am using Apache vfs sftp to copy a file to remote linux box and then rename it. copy works fine, but when i try to rename the file, it fails. I am using vfs 2.0 and jsch 0.1.50
Source(remoteFileTmp) : /tmp/abc.txt
Destination(remoteFileDest) : /home/myName/work/abc.txt
Command that I used is as below:
remoteFileTmp.moveTo(remoteFileDest);
The exception that i get is as below:
Exception in thread "main" java.lang.RuntimeException: org.apache.commons.vfs2.FileSystemException: Could not rename "sftp://hostname/tmp/abc.txt" to "sftp://hostname/home/myName/work/abc.txt".
at com.transfer.SFTPTransfer.uploadRename(SFTPTransfer.java:85)
at com.transfer.MainClass.main(MainClass.java:23)
Caused by: org.apache.commons.vfs2.FileSystemException: Could not rename "sftp://hostname/tmp/abc.txt" to "sftp://hostname/tmp/abc.txt" to "sftp://hostname/home/myName/work/abc.txt".
at org.apache.commons.vfs2.provider.AbstractFileObject.moveTo(AbstractFileObject.java:1116)
at com.transfer.SFTPTransfer.uploadRename(SFTPTransfer.java:59)
... 1 more
Caused by: 4: Failure
at com.jcraft.jsch.ChannelSftp.throwStatusError(ChannelSftp.java:2833)
at com.jcraft.jsch.ChannelSftp.rename(ChannelSftp.java:1910)
at org.apache.commons.vfs2.provider.sftp.SftpFileObject.doRename(SftpFileObject.java:289)
at org.apache.commons.vfs2.provider.AbstractFileObject.moveTo(AbstractFileObject.java:1102)
... 2 more
Directory /home/myName/work exists.
Note: when i try to move (rename) files in the same folder it works fine. i.e for the below input rename is succesfful.
source = /tmp/abc.txt
destination = /tmp/abc.txt_renamed
So is it that it supports rename only within the same directory?
Upvotes: 3
Views: 3038
Reputation: 744
This is caused by one of the open issues in the Apache VFS library when doing moveTo over SFTP :-(
https://issues.apache.org/jira/browse/VFS-590
and this
https://issues.apache.org/jira/browse/VFS-589
Upvotes: 2