tags:

views:

841

answers:

4

I'm SSHing into a remote server on the command line, and trying to copy a directory onto my local machine with the "scp" command, but the remove server gives back this "usage" message:

[Stewart:console/ebooks/discostat] jmm% scp -p ./styles/
usage: scp [-1246BCEpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
           [-l limit] [-o ssh_option] [-P port] [-S program]
           [[user@]host1:]file1 [...] [[user@]host2:]file2
[Stewart:console/ebooks/discostat] jmm%

I'd like to be able to transfer files in both directions. From what I read, I thought the above command would work for downloading, and "scp -p [localpath] [remotepath]" for uploading? Thx.

A: 

No, you still need to scp [from] [to] whichever way you're copying

The difference is, you need to scp -p server:serverpath localpath

Gareth
+9  A: 

You need to scp something somewhere. You have scp ./styles/, so you're saying secure copy ./styles/, but not where to copy it to.

Generally, if you want to download, it will go:

scp user@remote_host:remote_file local_file

where local_file might actually be a directory to put the file you're copying in. To upload, it's the opposite:

scp local_file user@remote_host:remote_file

If you want to copy a whole directory, you will need -r. Think of scp as like cp, except you can specify a file with user@remote_host:file as well as just local files.

Edit: As noted in a comment, if the usernames on the local and remote hosts are the same, then the user can be omitted when specifying a remote file.

lemnisca
Note that if the user is the same on the remote host and the local host, the username can be omitted: scp hello.c myserver.net:~/projects/
strager
Yes, true, I'll add a note about that. I included the user because then the examples I gave will always work. :)
lemnisca
+1: Added formatting to make it a little clearer.
Ken Gentle
Thanks, that looks better.
lemnisca
+1  A: 

If copying to/from your desktop machine, use WinSCP, or if on Linux, Nautilus supports SCP via the Connect To Server option.

scp can only copy files to a machine running sshd, hence you need to run the client software on the remote machine from the one you are running scp on.

If copying on the command line, use:

# copy from local machine to remote machine
scp localfile user@host:/path/to/whereyouwant/thefile

or

# copy from remote machine to local machine
scp user@host:/path/to/remotefile localfile
JeeBee
+2  A: 

You need to specify both source and destination, and if you want to copy directories you should look at the -r option.

So to recursively copy /home/user/whatever from remote server to your current directory:

scp -pr user@remoteserver:whatever .
Ken