Upload files with ssh / scp in Linux

Discussion in 'Shell / Command Line' started by Rob, Nov 21, 2011.

  1. Rob

    Rob Administrator Staff Member

    Messages:
    575
    Likes Received:
    217
    Trophy Points:
    43
    Throughout the day, you'll probably find yourself needing to upload files to various sites/servers. A great secure way to quickly move files around from server to server is to use the scp command. Let's say you need to copy a picture of a donut into your document root on server3.

    Code:
    scp /home/rob/pictures/donuts/half-eaten.jpg rob@server3:/home/mywebsite.com/public_html/images/
    
    Now, the picture "half-eaten.jpg" is on the mywebsite.com website in the images directory.. Let's work through the command:


    scp = our Linux command
    /home/rob/pictures/donuts/ = the directory where half-eaten.jpg resides
    half-eaten.jpg = our file
    rob@server3 = our username on server3
    /home/mywebsite.com/public_html/images/ = the directory on server3 where we'd like to put the image

    Let's try another one - say you need to grab the logo from that site so you can add a picture of a donut to it in gimp..
    Code:
    scp rob@server3:/home/mywebsite.com/public_html/images/mylogo.png /home/pictures/
    
    This will grab the logo and put it in your /home/pictures/ directory.

    This is a lot more fun if you have SSH keys set up, we also recommend using screen if you're going to be uploading things that may take a while.
  2. MustangV10

    MustangV10 New Member

    Messages:
    87
    Likes Received:
    3
    Trophy Points:
    0
    I don't understand how this works...are you copying files from your local pc or from another server or what?
  3. Victor Leigh

    Victor Leigh Member

    Messages:
    209
    Likes Received:
    8
    Trophy Points:
    18
    I think it works for anything so long as you know what's the source server and the destination server. Just curious. What does scp stand for? I would think the'cp' means 'copy', right?
  4. Rob

    Rob Administrator Staff Member

    Messages:
    575
    Likes Received:
    217
    Trophy Points:
    43
    Yes, from your local linux pc (or where ever your terminal is based.. 'server a')

    Picture it like command line ftp.
  5. Rob

    Rob Administrator Staff Member

    Messages:
    575
    Likes Received:
    217
    Trophy Points:
    43
    Yup.. you're right :)

    scp stands for 'secure cp' or 'secure copy'
  6. Victor Leigh

    Victor Leigh Member

    Messages:
    209
    Likes Received:
    8
    Trophy Points:
    18
    Thank you. Just curious. How does it become secure? Does it use an SSL connection like when we log into a https address?
  7. grim76

    grim76 Active Member Staff Writer

    Messages:
    177
    Likes Received:
    48
    Trophy Points:
    28
    This is using ssh to copy the files vs. using FTP or a non-encrypted protocol.
  8. ehansen

    ehansen New Member Staff Writer

    Messages:
    115
    Likes Received:
    11
    Trophy Points:
    0
    Adding SSH keys to the mix also makes it far more secure due to the fact your password won't be transmitted via plain-text. :) But, screen is useful I find only if you do not have a tab-capable terminal (i.e.: using putty or a GUI-less box). Its still a very powerful and useful tool, but I think people often overlook the capabilities of terminal emulators (like Konsole) these days.
  9. goodselfme

    goodselfme New Member

    Messages:
    11
    Likes Received:
    0
    Trophy Points:
    0
    Even the questions are helping me to better understand applications. You have some very smart people on this forum. Thank you to all of you assisting me.
  10. carbon333

    carbon333 New Member

    Messages:
    87
    Likes Received:
    6
    Trophy Points:
    0
    The option -r is also worth mentoning. It copies a dir recursively.
  11. Akendo

    Akendo New Member

    Messages:
    136
    Likes Received:
    7
    Trophy Points:
    0
    I wanted to reply to this post, but it has gone to far. So i pushed it out on a blog post.
  12. arcteryx

    arcteryx New Member

    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    upload files in folder

    I have a question, I've seen this command before and have been trying it out by uploading multiple files in a folder and was unsuccessful. Would this be possible to work? I tried the command with a recursive '-R' and a wildcard at the end of the directory.

    Thanks!
  13. user

    user New Member

    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I am sorry to reply something unrelavant to your post. But I need help.
    I don't know how to create new post. I look everywhere, But find no such a button to create new post. Please help!
  14. Schlittenhund

    Schlittenhund New Member

    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    0
    -R is not -r. Most Linux developers don't allow case insensitivity in user input.

    What's an example of your command?

    There's an orange button right around where the Reply To Thread button is. You have to be inside one of the main forums.
  15. Mohanasmith

    Mohanasmith New Member

    Messages:
    21
    Likes Received:
    0
    Trophy Points:
    1
    its really complicated one to understand, making me frustated now, i dont think it an easy one to go through
  16. Maverick1

    Maverick1 New Member

    Messages:
    24
    Likes Received:
    5
    Trophy Points:
    3
  17. Brandon Doyle

    Brandon Doyle New Member

    Messages:
    14
    Likes Received:
    3
    Trophy Points:
    3
    I'm trying to copy files from my laptop to my server in the basement with this command and it won't work. Perhaps you could give me some advice? Below is the command I've tried:

    sudo scp /home/brandon/Documents/3011.jpg brandon@111.111.1.11:/var/www/brandon-PC/

    It always tells me the following:

    The authenticity of host '111.111.1.11 (111.111.1.11)' can't be established. ECDSA key fingerprint is 00:00:00:00:00:00:00:00:00:00:00:00:00:00:00:00. Are you sure you want to continue connecting (yes/no)?

    And every time I say "y" it just asks me again and again and again and again...

    Please tell me what I'm doing wrong.

    Brandon Doyle

Share This Page