Is there a way, using sftp, to copy a file on a remote file system to the same file system?

Most SFTP servers do not support duplication of a remote file.

There's copy-file extension to SFTP protocol. But it's supported by few SFTP servers only. For example by ProFTPD/mod_sftp and Bitvise WinSSHD. It's not supported by the most widespread SFTP server, the OpenSSH.


Quite often, when you have an SFTP access, you also have an SSH shell access. Then you can copy the files using shell commands (like cp in *nix).


Unfortunately, the answer is no: the ftp/sftp protocol does not allow an offloaded remote copy.


Not really "using sftp", but since sftp uses SSH, can't you just log on the remote server using ssh, and copy your file normally ?

Another alternative I would consider would be using sshfs, which lets you mount your ssh dir as a virtual drive, and use commands like cp on it. I'm not sure about the performance, but it can be worth trying. This works even if your shell is disabled with something like /bin/false, which can be pretty handy.


As indicated by previous answers, the protocol does not support what you need. You can work around this by downloading the file, renaming the downloaded copy on your own machine, and then upload it again. This is bulky, but if done as a part of an sftp script it does not really matter.

get file.txt
!mv file.txt copy_of_file.txt
put copy_of_file.txt