I have backup space that is accessible by SFTP. I have made a backup in a directory called "mybackup" on this remote storage. I would now like to make a copy of the mybackup directory called "mybackup-copy" also on the remote storage.

Is there a way to do this with SFTP that doesn't involve downloading the whole directory and then re-uploading the whole directory?

As in, if I had full SSH shell access I could do cp -ar mybackup mybackup-copy - can this be achieved with the sftp protocol?

  • Can you use scp? When using scp remote_location1 remote_location2, scp copies directly between location1 and location2, unless you use -3 parameter. -3 transfers files from remote 1 to the machine performing the scp command, and then to remote2. I suspect scp without -3 might be able to do it. man7.org/linux/man-pages/man1/scp.1.html
    – nobody
    Nov 9 '20 at 12:26
  • @nobody I got hopeful on that, but no, seems that's not supported by the host. Good tip though, thanks! Nov 9 '20 at 16:18

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

There's draft of the 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.

It's definitely not supported by the most widespread OpenSSH SFTP server. Nor by OpenSSH SFTP client (sftp), i.e. there's no cp command or any other functionally equivalent.

So using the shell cp command is typically the only way.


If the remote end supports scp this should work:

scp -p host:/path/to/file/filename.ext host:/path/to/copy/of/file/

Or, since you say you're seeking to copy a directory:

scp -rp host:/path/to/directory host:/path/to/copy/

Assuming that directory /path/to/copy exists on host, the latter command will result in a new directory /path/to/copy/directory on host.

  • Thanks but was asking about SFTP because SCP not available - see above. May 28 at 8:45
  • @artfulrobot It never hurts to check, since the underlying protocol is similar. I know I personally have deployed sites that support sftp, scp and rsync, since they're all based on the SSH protocol.
    – Jim L.
    May 28 at 16:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.