Move remote file using JSCH
I need to move a remote file into a subdirectory using the JSCH library for SFTP. I tried a simple ChannelSftp.rename(filename, subdir + File.separator + filename), but as a result I get the file renamed to subdir+filename in the same directory. Any hint, how this can be done?
Re: Move remote file using JSCH
I don't know whether or not it will make any difference but to quote section 6.2 (File names) in draft-ietf-secsh-filexfer-02 ( which is what OpenSSH conforms to ) -
"This protocol represents file names as strings. File names are
assumed to use the slash (’/’) character as a directory separator."
so one should use a '/' not File.separator . Note - this will not allow you to move a file from one volume to another; only to rename a file on a a volume.
I have been working with the SFTP specification for a couple of months and very early on I realised that the specifications are written round what had already been implemented in *Nix and not what should be implemented. There is no attempt to abstract features so that a sensible implementation on OS other than *Nix can conform. The biggest example of this is the specification of the 'longname' files in entries in file lists i.e.
"The recommended format for the longname field is as follows: -rwxr-xr-x 1 mjos staff 348911 Mar 25 14:29 t-filexfer
1234567890 123 12345678 12345678 12345678 123456789012"
which is what one gets from the *Nix 'ls' command and assumes an 'owner/group/world' that just is not available on Windows and using pre-1.7 JDK is not available in Java even for *Nix.