5

As OpenSSH guys said "The scp protocol is outdated", it's time to think about post-scp days.

However sftp seems to be designed to interactive operation. Is there good way to use sftp command like scp? means, how to do this on sftp?

scp ./myfile myserver:/home/myfile

Or, any good scp successor?

0
5

sftp command is indeed built around commands (like ftp). So it cannot work as an in-place replacement for scp.

Though you can use one-liners like:

echo get /remote/path/file.txt /local/path.txt | sftp user@example.com

or

echo put /local/path.txt /remote/path/file.txt | sftp user@example.com

You may want to add -b - to force a non-interactive mode.


Interestingly (as @Kamil mentioned), for downloads, you can also use this scp-like syntax:

sftp user@example.com:/remote/path/file.txt /local/path.txt

(the use of the second argument is not documented).

Use of sftp:// prefix is also possible since OpenSSH 7.7, which somewhat modifies the syntax (allows URL encoding of the username and the path).


There's also free/open-source pscp command-line client that comes in PuTTY package, which is available for Linux (while more commonly used on Windows). It has an identical command-line interface to OpenSSH scp. But contrary to its name and scp, it's primarily SFTP client (while it can fallback to SCP, if the server does not support SFTP).

Despite its name, PSCP (like many other ostensible scp clients) can use either of these protocols.

...

Normally PSCP will attempt to use the SFTP protocol, and only fall back to the SCP protocol if SFTP is not available on the server.

You can install PuTTY/pscp with apt-get like:

sudo apt-get install -y putty

There's similar question on Stack Overflow: Single line sftp from terminal

0
0

You should also consider rsync. Except for the remote1-to-remote2 transfer that scp allows, it appears -- from a quick read of man scp anyway -- that you could make rsync do all of that quite easily, or write a wrapper that is not too painless.

Rsync has other advantages that you get by default (viz., much more efficient when replacing an older file), even if you don't use any of it's many options.

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.