?
Solved

Using SSH can I quickly copy between my local HD and the remote server?

Posted on 2009-04-14
17
Medium Priority
?
266 Views
Last Modified: 2013-12-26
Hello everybody!

I am running Ubuntu, and using my terminal to ssh into a remote server.  What is the best way to transfer files between the remote server and my local hard drive.

I tried using 'scp' and it only seemed to work if I am running it on my local computer and not while I am SSHing.  Any ideas or recommendations?
0
Comment
Question by:parlays
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
  • +2
17 Comments
 
LVL 48

Expert Comment

by:Tintin
ID: 24144123
Are you saying that if you ssh to the remote server, and then do a scp to/from the remote server it doesn't transfer the files?

Do you get any error messages?
0
 
LVL 7

Assisted Solution

by:martin_2110
martin_2110 earned 400 total points
ID: 24144209
rsync -a -v --stats --progress /local/file/path root@remoteserver:/remote/file/path
0
 
LVL 7

Expert Comment

by:martin_2110
ID: 24144215
the above command should be run on your local desktops terminal.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:parlays
ID: 24144311
What i would like to do is to SSH into the remote server.  From there I would like to type a command to copy files from my local hard drive?  When I try using SCP, I have no idea what to type as the source because my local hard drive doesn't have a domain name.  You know what I mean.
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 400 total points
ID: 24144321
No need to ssh to the remote server first.

On the local server, just do

scp /path/to/your/files* user@remote-server:/some/path
0
 

Author Comment

by:parlays
ID: 24144418
How do I do it the other way around?  Once I am SSHed into the remote server how do I copy from my local hd?
0
 
LVL 48

Expert Comment

by:Tintin
ID: 24144480
If you are on the remote server, you do

scp user@you-local-server:/path/to/files* /some/path

0
 

Author Comment

by:parlays
ID: 24144684
'your-local-server' ?

That's what I need to figure out.

What is my local server?  'localhost'?  i'll try that, but isn't there a way to specify to grab from my local drive other than using a server name?
0
 
LVL 51

Expert Comment

by:Steve Bink
ID: 24144766
Use the IP.  'localhost' is always the local system, in context.  That means if you SSH into the remote server, 'localhost' means the remote server's local system.
0
 

Author Comment

by:parlays
ID: 24144774
Gotcha, i'll get my IP address of the router, checking what it is with 'ifconfig'.  Is that correct?

I'll test it out tomorrow, thanks for your help.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 24144801
You don't want the IP address of your router, unless your local server also acts as the router.

If you are behind a firewall and/or have a NATed address, then you are going to run into difficulties.
0
 

Author Comment

by:parlays
ID: 24144813
Well picture my setup.  I'm on a laptop running Ubuntu connected to the internet through a router.

I connect to a remote server using the terminal, and now using SSH on the remote server I want to copy a file from my local hard drive on the laptop.

The laptop i'm using I don't think has an IP address?  Can I connect to it?  Or is the only way to use 'scp' from the local hard drive to the remote server?
0
 
LVL 48

Assisted Solution

by:Tintin
Tintin earned 400 total points
ID: 24144839
In order for your laptop to connect to anything, it has to have an IP address.  

Type

ifconfig -a

to see what it is.

It is possible you are getting your IP address via DHCP off your router.  It's also quite likely you are using a NATed IP address.

Why don't you want to copy from your local server to the remote server rather than the other way round?
0
 
LVL 51

Assisted Solution

by:Steve Bink
Steve Bink earned 200 total points
ID: 24144904
>>> Why don't you want to copy from your local server to the remote server rather than the other way round?

I thought the same thing just after I posted...Why not initiate scp from your laptop instead?  If you're using Windows on the laptop, try www.winscp.com.  It is an FTP/SFTP/SCP client for Windows that works great, even through NAT'd routers.

Otherwise, you are correct...you'll need the public address of your router to hit back to your network.  Also, your router should be pushing port 22 to your laptop's IP.  This is not such a great solution, since that means your laptop is now receiving every SSH request from the internet-at-large.
0
 

Author Comment

by:parlays
ID: 24144913
Cool, I hear ya.  I'm just trying to see what is possible and learn the best way to copy files.  Still new to using these tools.

I have no prob copying from the local to the remote server.  Thanks for all the help and responses fellas.
0
 
LVL 5

Accepted Solution

by:
dcesari earned 1000 total points
ID: 24145467
Hi, there is still one simple thing you can do, if you really want to initiate the copy from the server: opening a ssh tunnel, try the following:

from the laptop:
ssh -R 60001:localhost:22 yourserveruser@remoteserver

this opens an usual ssh connection on the server host which also listen for connections on port 60001, redirecting them to your laptop's ssh daemon (port 22); then, on the server, any command like

ssh -p 60001 yourlaptopuser@localhost
scp -P 60001 file_on_server yourlaptopuser@localhost:dir_on_laptop/

will work and will login or copy file to your laptop through its ssh daemon, notice that here localhost must be really "localhost", it is not an example name, and also -p for ssh, -P for scp is not a typo (see man pages); 60001 can be actually any free port number 65536>p>32767. This will work as long as your initial ssh connection to the server is active.
From a security point of view, this will allow ssh connection to your laptop to:

1. any user on the server
2. any user on the internet (provided that the server is open to internet) connecting to it on port 60001

the second may not be a big issue, because it is unlikely that anyone will try a ssh connection on random ports (but I may be wrong!?), on the other side, for point n.1, from inside the server someone my have the ability to check the active connections and detect your tunnel, anyway still better than opening the sshd to the whole internet on port 22.
0
 
LVL 5

Expert Comment

by:dcesari
ID: 24313071
Any progress on this side? Did you test the tunnel solution?
0

Featured Post

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello to you all, I hear of many people congratulate AWS (Amazon Web Services) on how easy it is to spin up and create new EC2 (Elastic Compute Cloud) instances, but then fail and struggle to connect to them using simple tools such as SSH (Secure…
Google Drive is extremely cheap offsite storage, and it's even possible to get extra storage for free for two years.  You can use the free account 15GB, and if you have an Android device..when you install Google Drive for the first time it will give…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses
Course of the Month12 days, 16 hours left to enroll

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question