How can I copy/duplicate a file to another directory using SFTP?

The core SFTP protocol does not support duplicating a remote file.

There’s draft of copy-file extension to the protocol. But that’s supported by only few SFTP servers (ProFTPD mod_sftp and Bitvise SFTP server for example) and few SFTP clients (WinSCP for example).

The most widespread SFTP server, the OpenSSH supports related copy-data only in very recent version 9.0. Its sftp client has now cp/copy command.


Alternatives:

  • If you have SSH/terminal access into the server, use the shell cp command.
  • If your SFTP server supports the copy-file extension, use an SFTP client that supports it too.
  • Otherwise, your only option is to download the file to a local temporary location and upload its copy back to a different/target remote directory.
    Some SFTP clients can do this for you even transparently in one go (e.g. in WinSCP, see Duplicate via local temporary copy option on Duplicate dialog).

(I’m the author of WinSCP)

Leave a Comment