Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
412 views
in Technique[技术] by (71.8m points)

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

I have created a directory within an SFTP location and I want to move a file from one SFTP directory to another directory but cp command is not supported there.

How can I achieve this?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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).

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.


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)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...