2. To copy files from a local system to remote server or remote server
to local system, we can use the command 'scp‘
'scp' stands for 'secure copy‘
It is a command used for copying files through terminal
We can use 'scp' in Linux, Windows and Mac.
INTRODUCTION
3. The basic syntax for copying files from local system to remote server is,
“ scp source/filename [username]@[host]:destination ”
Here,
Source is the source location, i.e, from where we want to copy files
Username is the user in the remote system
Host is the address of the server
Destination means the location to which we want to copy files.
Copying Single File To Server From Local System
Example : scp /home/myfile.docx root@example.com:/opt/odoo/
4. Syntax is,
“ scp [username]@[host]:source/filename [destination] ”
Example:
scp root@example.com:/opt/odoo/myfile.docx /home/
Copying Single File From Server To Local System
5. If we need to copy multiple files from a location instead of copying
the complete folder, we can achieve this by specifying the required files
in the same command separated by space. i.e., it should be like,
scp source/file file2 file3 [user@server]/destination
If needed, it is also possible to copy from different locations. We just
need to provide them in a space separated list.
Copying Multiple Files
6. Suppose we need to transfer a folder and its contents from a server or to
a server instead of a file, we need a small change in the command.
We need to use '-r' to specify that we need to recursively process the
folder and its contents.
Copying Folder
7. Example:
scp -r /home/myfolder root@example.com:/opt/odoo/
It will copy the folder and all the files in the folder to the destination
location.
scp -r /home/myfolder/* root@example.com:/opt/odoo/
This command will copy all the files in the specified location to the
destination
Copying Folder
8. It is also possible to copy files between two remote servers. If we need to
copy files from server-1 to server-2, we can use the following command,
scp [user@server-1]/source/file [user@server-2]/destination/
9. To copy files to the server at a specific port, we need to make some
changes in the ssh configuration.
First we need to install ssh, typing the command
“apt-get install openssh-server”
Copy Files To A Specific Port (Linux)
10. After ssh is installed, go to /etc/ssh/ and edit the file sshd_config as root.
Change the port number to the one which we want to use.
By default, the port is set to 22.
We can change it.
After changing the port number, we may need to restart ssh.
/etc/init.d/ssh restart
11. Now we have set a new port for listening ssh
In order to copy files, we may need to specify the port number also.
It should be like this,
scp -P [port-no] [user@server]/source/file destination