Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how do I scp a file
#1

first of all what is scp ?

 

here's a quote direct from the top of the command

 



Code:
man scp




 

Quote:SCP(1) BSD General Commands Manual SCP(1) 

NAME

scp - secure copy (remote file copy program)

 

SYNOPSIS

scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]

[-l limit] [-o ssh_option] [-P port] [-S program]

[[user@]host1:]file1 [...] [[user@]host2:]file2
 

it's the same as cp (copy) except secure as you are doing it over an ssh connection. When you start an scp session to a target box, you will be prompted for the users ssh password, this is normal and signifys to you that this is a secure transfer.

 

here's the usage



Code:
scp -prP port file user@ip:./




 

where port=the ssh listening port on the target linux box

where file=the file you want to send to the target

where user=the username you ssh in as

where ip=the ip address of the target box

where :./=the home directory of the user you are ssh'ing as

 

and

 

-p =Preserves modification times, access times, and modes from the original file.

-P=capital P for port as -p is already taken from above.

-r=recursively copy entire directories.

 

so a real example of the above would be like

 

Quote:[anyweb@localhost ~]$ scp -prP 1234 SC_160_P_ESD1.zip anyweb@213.64.12.34:./anyweb@213.64.12.34's password:

SC_160_P_ESD1.zip 100% 29MB 255.2KB/s 01:58
 

thanks to P38 and jY for the advice.

 

cheers

anyweb

Reply
#2
if you need some more scp examples
Reply
#3

I'd also add that another option is to use the "sftp" command. Essentially a FTP-like interactive shell but utilising SSH.

 

I find SCP is good for copying one or two files, but SFTP is easier for yanking several at a time (such as an entire directory).

 

Also check out "rsync" for keeping a mirrored server up to date with its original data.

Reply
#4
feel free to give us some examples of doing this, i must confess to using the scp method quite a bit but any cli alternative is appreciated :)
Reply
#5

In its simplest form, use:



Code:
sftp remote.host




 

To use a different username:



Code:
sftp fred@remote.host




 

To use other SSH options, such as specifying a different SSH port number:



Code:
sftp -oPort=65422 fred@remote.host
Connecting to remote.host...
fred@remote.host's password:




 

Once connected, use "help" at the prompt for assistance:



Code:
sftp> help
Available commands:
cd path                       Change remote directory to 'path'
lcd path                      Change local directory to 'path'
chgrp grp path                Change group of file 'path' to 'grp'
chmod mode path               Change permissions of file 'path' to 'mode'
chown own path                Change owner of file 'path' to 'own'
help                          Display this help text
get remote-path [local-path]  Download file
lls [ls-options [path]]       Display local directory listing
ln oldpath newpath            Symlink remote file
lmkdir path                   Create local directory
lpwd                          Print local working directory
ls [path]                     Display remote directory listing
lumask umask                  Set local umask to 'umask'
mkdir path                    Create remote directory
progress                      Toggle display of progress meter
put local-path [remote-path]  Upload file
pwd                           Display remote working directory
exit                          Quit sftp
quit                          Quit sftp
rename oldpath newpath        Rename remote file
rmdir path                    Remove remote directory
rm path                       Delete remote file
symlink oldpath newpath       Symlink remote file
version                       Show SFTP version
!command                      Execute 'command' in local shell
!                             Escape to local shell
?                             Synonym for help




Many FTP commands work in SFTP:

 

"cd" to change directory on remote host

"lcd" to change local directory (useful if you started the SFTP session in the wrong directory!)

"get myfile" to download that file from remote host to local directory

"put newfile" to upload a local file to the remote host

"mget *.txt" to download all files matching that pattern (shell globbing expression, not regular expression)

 

Hope that's enough to go on!

Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)