195

Usually, I use the scp command to transfer files on *nixes.

What's the difference between SFTP and SCP? Don't they both work on SSH?

5 Answers 5

123

In a nutshell, SCP can only be used for transferring files, and it is non-interactive (i.e., everything has to be specified on the command line). SFTP is more elaborate, and allows interactive commands to do things like creating directories, deleting directories and files (all subject to system permissions, of course), etc.

3
  • 44
    Regarding interactivity: The difference you describe is about specific SFTP/SCP clients as implemented in OpenSSH. It's nothing about the protocols themselves. It's perfectly possible to implement interactive SCP client or non-interactive SFTP client. Oct 8, 2014 at 6:06
  • 6
    One more thing: scp does not work if the server only permits SFTP access via the line ForceCommand internal-sftp. I think PermitTTY no also prevents scp access but allows sftp access, though I could have just mistyped my password every single time I tried. But those two things should not prevent sftp. Source: personal experience.
    – ecube
    Oct 10, 2016 at 7:27
  • 3
    In the future, scp can access files over ssh despite ForceCommand internal-sftp, because there is some work being done here: github.com/openssh/openssh-portable/pull/194 That would solve the issue that @ecube mentioned.
    – Rob W
    Oct 11, 2020 at 18:26
114

From Wikipedia:

Compared to the earlier SCP protocol, which allows only file transfers, the SFTP protocol allows for a range of operations on remote files – it is more like a remote file system protocol. An SFTP client's extra capabilities compared to an SCP client include resuming interrupted transfers, directory listings, and remote file removal. [1] For these reasons it is relatively simple to implement a GUI SFTP client compared with a GUI SCP client.

and

Although both SCP and SFTP utilize the same SSH encryption during file transfer with the same general level of overhead, SCP is usually much faster than SFTP at transferring files, especially on high latency networks. This happens because SCP implements a more efficient transfer algorithm, one which does not require waiting for packet confirmations. This leads to faster speed but comes at the expense of not being able to interrupt a transfer, so unlike SFTP, SCP transfer cannot be canceled without terminating the session.

3
  • 21
    "SCP is usually much faster than SFTP at transferring files." Oct 4, 2013 at 10:35
  • 8
    "But comes at the expense of not being able to interrupt a transfer". That's a pretty important trade-off.
    – aaaaaa
    Jun 25, 2016 at 1:42
  • 1
    aaaaaa, "without terminating the session" which is not a big deal if all the session is for is copying the file. If you are copying a lot of files, the client can also wait for an individual file copy to complete. Sep 18, 2019 at 18:56
16

From a purely command line perspective :

  • scp doesn't have an interactive mode nor can it read command scripts, that means everything must be written on the command line.
  • sftp has an interactive mode and can read commands from a file.

Other important difference between the 2 commands is that sftp cannot put a local file to a remote location using a single command line, although it can get remote file, while scp can do both.

sftp get remote file

sftp user@host:/path/to/remote.file [/path/to/local.file]

scp get remote file

scp user@host:/path/to/remote.file [/path/to/local.file]

scp put remote file

scp /path/to/local.file user@host:[/path/to/remote.file]
1
  • 5
    Putting a file: sftp {user}@{host}:{remote_dir} <<< $'put {local_file_path}'
    – gdw2
    Apr 18, 2019 at 17:16
5

SSH (Secure SHell) is a cryptographic network protocol to allow remote login and other network services to operate securely over an unsecured network.

Differences: SFTP is works on interactive mode (session) and SCP works on non-interactive. Using SFTP we can access remote file system i.e. creating, deleting, and listing files.

Similarities: Both SCP(Secure Copy Protocol) and SFTP (SSH File Transfer Protocol) are network protocols, which supports file management between hosts on a network. Both uses SSH.

more

5

Most differences of the two protocols have already been said in other answers, and more verbosely in https://unix.stackexchange.com/q/8707/19088

Another difference, according to the documentation of curl, is that the SCP protocol is not very portable and usually only works between Unix systems.

By the way, curl implements both protocols and unlike the default OpenSSH SFTP client implementation, it is non-interactive for both SFTP and SCP.

And note that there is also the FISH protocol, which allows you to transfer files via SSH without the need of SCP or SFTP. As far as I know FISH is not very popular, currently implemented in just a few file managers (Midnight Commander and some that are KDE-based) and Lftp.

2
  • 3
    "Another difference, according to the documentation of curl, is that the SCP protocol is not very portable and usually only works between Unix systems." The irony of this part of your answer is that the most popular SCP GUI is called WinSCP, and - you've guessed it - it is a Windows Program.
    – brett
    Feb 26, 2018 at 18:11
  • 2
    @brett the most popular client is probably OpenSSH's scp, I would say it is highly deployed. WinSCP is an SCP/SFTP/etc client but is nowadays mostly used as an (S)FTP client: "In June 2003 version 3.0 was released, introducing support for the alternative to SCP, the SFTP protocol. Over time it evolved from the alternative to the primary protocol. Despite this, the well-established name “WinSCP” was preserved." (from History of WinSCP: winscp.net/eng/docs/project_history)
    – Pere
    Feb 26, 2018 at 21:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .