In an SFTP session is it possible to copy one remo

2019-01-27 03:27发布

问题:

Let say I have a file /home/user/dir1/file.txt on a remote SFTP server. I want to copy this file to lets say /home/user/dir2/file.txt, while I am in a sftp session (I have server which allows only sftp connections, but no ssh connections!) connected to this server?

Is it possible to do so? If yes, what is the command?

For example the following command would rename move a file from one directory to another on the remote server.

sftp> rename dir1/file.txt dir2/file.txt

I am looking for a command which would copy a file from one directory to another on the remote server, if one exists.

The work around is to download the file from first location and upload to the second location, but that is not an option when the file in question is a big one and one is working with a slow network connection!

回答1:

Not sure what you mean by the "command". Are you referring to an SFTP protocol request? Or a command of some scriptable/command-line SFTP client (e.g. the OpenSSH sftp)?

The SFTP protocol on its own does not allow duplication of a remote file. Though there's an optional extension of the protocol named copy-file that serves the purpose.

Quoting the copy-file extension specification:

6. Copying Remote Files

byte   SSH_FXP_EXTENDED
uint32 request-id
string "copy-file"
string source-file
string destination-file
bool   overwrite-destination

This request copies a file from one location to another on the server. The server responds with SSH_FXP_STATUS.

Not many SFTP servers support the extension though. I know that ProFTPD/mod_sftp and Bitvise WinSSHD do. Notably, the OpenSSH does not (neither the server, nor the sftp client).



标签: copy sftp