scp – Secure Copy Command

About a year ago, I was forced to move away from using FTP and start using SCP (secure cp) to transfer files between our Linux servers. SCP is available on other UNIX systems and easy enough to use. Problem is I don’t use it often enough and forget the syntax when I need it.

Syntax to copy the file “mike.txt” from a remote host to the local host:

# scp username@remotehost_name:/path/mike.txt /local_dir

Example of copying file to current directory location:

# scp root@srvr02.domain.com:/d01/dbbackup/jiradb.bkp .

The authenticity of host ‘srvr02.domain.com (xxx.xx.xxx.xx)’ can’t be established.
RSA key fingerprint is <hexadecimal_output>.

Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘srvr02.domain.com’ (RSA) to the list of known hosts.
root@srvr02.domain.com’s password:

jiradb.bkp 100% 51MB 1.8MB/s 00:28

Additional Information
WinSCP is an open source SFTP client for Windows.

Update (17-Sep-2009)
Additional SCP syntax information found here.

Update (29-Aug-2008)
SCP automation tip from Santhosh Tirunahari’s blog Think Beyond Technology.

Advertisements

4 Responses to scp – Secure Copy Command

  1. kevinclosson says:

    good post…

    I’d like to add for your readers that unlike cp(1), scp does not protect against multiple file clobbering… that is, cp(1) will not let you string multiple files out unless that last arg to the command is a directory. On the other hand, if you list out a bunch of files for scp and accidentally hit return before the the hostname:/path arg on the end, your last file in the arg list will get clobbered:

    [root@tmr6s13 SCP]# echo 1 > f.1
    [root@tmr6s13 SCP]# echo 2 > f.2
    [root@tmr6s13 SCP]# echo 3 > f.3
    [root@tmr6s13 SCP]# scp f.1 f.2 f.3
    [root@tmr6s13 SCP]# cat f.3
    2
    [root@tmr6s13 SCP]# cat f.1
    1
    [root@tmr6s13 SCP]# cat f.2
    2

    Unlike cp(1):

    [root@tmr6s13 SCP]# cp f.1 f.2 f.3
    cp: copying multiple files, but last argument `f.3′ is not a directory
    Try `cp –help’ for more information.

    Anyone who reads my blog knows I’m prone to typos… let’s just say I’ve hit return too fast on a multifile scp command before :-)

    HIH

    PS. I like your blog

  2. mrothouse says:

    Excellent point to remember Kevin. Thanks!

    I enjoy your blog as well. An abundance of valuable content to be found there. Thanks for sharing.

  3. Johne182 says:

    I am so grateful for your blog article.Really thank you! Fantastic. gcafedededce

  4. casino crazy fruit machine emulator

    scp – Secure Copy Command | Mike R’s Blog

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: