Solved

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

Posted on 2009-04-14
17
264 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 100 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

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 100 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 50

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 100 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 50

Assisted Solution

by:Steve Bink
Steve Bink earned 50 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 250 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

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

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

Secure Shell (SSH) is a network protocol for secure data communication, mainly used to administer remote Unix / Linux servers via command line. But it also allows the user to open a secure tunnel between a client and a server where he can send any k…
When it comes to security, there are always trade-offs between security and convenience/ease of administration. This article examines some of the main pros and cons of using key authentication vs password authentication for hosting an SFTP server.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

739 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