53

In my terminal shell, I ssh'ed into a remote server, and I cd to the directory I want. Now in this directory, there is a file called table that I want to copy to my local machine /home/me/Desktop. How can I do this?

I tried scp table /home/me/Desktop but it gave an error about no such file or directory. Does anyone know how to do this?

Thanks

omega
  • 40,311
  • 81
  • 251
  • 474
  • in this can a remote sever be in a different network and local machine in different network?? – Raulp Aug 25 '21 at 08:49

4 Answers4

84

For example, your remote host is example.com and remote login name is user1:

scp user1@example.com:/path/to/file /path/to/store/file
kkpoon
  • 1,939
  • 13
  • 23
  • 20
    what if I am on server? – Ramesh Pareek Jul 12 '17 at 01:14
  • 1
    how about `scp /path/to/local/file user1@otherhost:/path/to/file` – kkpoon Jul 24 '17 at 09:41
  • @kkpoon what if I am on server, and want to copy files from server to local? – zheyuanWang Aug 09 '21 at 02:15
  • If you are on the server and want to copy the file(s) to your local machine, doesn't your local machine also have to be an ssh server? – Quantifier Aug 11 '21 at 22:22
  • 1
    Log out of remote server. `scp` uses `ssh` below the surface. So if you give an `scp` command on your local machine, `scp` will `ssh` onto your server to copy the file. If you normally do `ssh my-user@my-server`, now do `scp my-user@my-server:/my/path/to/my.remote.file /my/path/to/my.local.file` – Stijn de Witt Sep 26 '22 at 10:21
8

The scp operation is separate from your ssh login. You will need to issue an ssh command similar to the following one assuming jdoe is account with which you log into the remote system and that the remote system is example.com:

scp jdoe@example.com:/somedir/table /home/me/Desktop/.

The scp command issued from the system where /home/me/Desktop resides is followed by the userid for the account on the remote server. You then add a ":" followed by the directory path and file name on the remote server, e.g., /somedir/table. Then add a space and the location to which you want to copy the file. If you want the file to have the same name on the client system, you can indicate that with a period, i.e. "." at the end of the directory path; if you want a different name you could use /home/me/Desktop/newname, instead. If you were using a nonstandard port for SSH connections, you would need to specify that port with a "-P n" (capital P), where "n" is the port number. The standard port is 22 and if you aren't specifying it for the SSH connection then you won't need that.

MoonPoint
  • 171
  • 3
6

When you use scp you have to tell the host name and ip address from where you want to copy the file. For instance, if you are at the remote host and you want to transfer the file to your pc you may use something like this:

scp -P[portnumber] myfile_at_remote_host [user]@[your_ip_address]:/your/path/

Example:

scp -P22 table fake_user@111.111.111.11:/home/me/Desktop/

On the other hand, if you are at your are actually on your machine you may use something like this:

scp -P[portnumber] [remote_login]@[remote's_ip_address]:/remote/path/myfile_at_remote_host /your/path/

Example:

scp -P22 [fake_user]@222.222.222.222:/remote/path/table /home/me/Desktop/

dgsleeps
  • 700
  • 6
  • 7
1

I would recommend to use sftp, use this command sftp -oPort=7777 user@host where -oPort is custom port number of ssh , in case if u changed it to 7777, then u can use -oPort, else if use only port 22 then plain sftp user@host which asks for the password , then u can log in, and u can navigate to required location using cd /home/user then a simple command get table u can download it, If u want to download a directory/folder get -r someDirectory will do it. If u want the file permissions also to exist then get -Pr someDirectory. For uploading on to remote change get to put in above commands.

TEDDY
  • 821
  • 10
  • 24