How do I transfer files from Linux server to local machine?

scp command is being used to copy files from a remote server to a local machine and vice versa. It uses ssh to do secure file transfer.

1. Copy a file from a remote server to a local machine

It will ask the password for remote user

* symbol can be used to copy multiple files by pattern like w3docs* which will copy w3docs.sql, w3docs1.pdf and etc.

2. Copy a directory from a remote server to a local machine

-r should be used for directories

3. Copy a file from a local machine to a remote server

4. Copy a directory from a local machine to a remote server

-r should be used for directories

5. Copy files by using RSA keys

If there is an identity key (RSA) instead of password than -i should be added

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

asked Mar 5, 2015 at 2:32

1

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

scp :/path/to/file /path/to/store/file

answered Mar 5, 2015 at 2:43

kkpoonkkpoon

1,89913 silver badges23 bronze badges

5

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 :/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.

answered Mar 5, 2015 at 2:52

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 :/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/

answered Mar 5, 2015 at 2:39

dgsleepsdgsleeps

6906 silver badges7 bronze badges

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.

answered Mar 5, 2015 at 5:38

TEDDYTEDDY

81110 silver badges24 bronze badges

How can I download a file from a Linux server to my local machine?

wget and curl are just two of the most popular commands for downloading files in Linux. There are more such command line tools. Terminal based web-browsers like elinks, w3m etc can also be used for downloading files in command line. Personally, for a simple download, I prefer using wget over curl.

How to copy folder from remote server to local machine in Linux?

You can use either scp or rsync to copy folder and files from local to ssh or copy folder and files from ssh to local within in the same or different directory. By default copy files and folders happen sequentially. If you wish to copy directory and contents in parallel then you must use pscp or pssh tool.