Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 272
  • Last Modified:

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

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
parlays
Asked:
parlays
  • 6
  • 5
  • 2
  • +2
5 Solutions
 
TintinCommented:
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
 
martin_2110Commented:
rsync -a -v --stats --progress /local/file/path root@remoteserver:/remote/file/path
0
 
martin_2110Commented:
the above command should be run on your local desktops terminal.
0
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
parlaysAuthor Commented:
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
 
TintinCommented:
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
 
parlaysAuthor Commented:
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
 
TintinCommented:
If you are on the remote server, you do

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

0
 
parlaysAuthor Commented:
'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
 
Steve BinkCommented:
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
 
parlaysAuthor Commented:
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
 
TintinCommented:
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
 
parlaysAuthor Commented:
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
 
TintinCommented:
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
 
Steve BinkCommented:
>>> 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
 
parlaysAuthor Commented:
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
 
dcesariCommented:
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
 
dcesariCommented:
Any progress on this side? Did you test the tunnel solution?
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
  • 5
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now