Compress and transfer files to remote server using SCP command

Caution this process will take disk space on host system, if u want to SCP and compress at the same time, with no intermediate save then read this article :- https://linuxguides.net/compress-and-transfer-at-the-same-time-using-ssh/

If u want to create and transfer a archive from your server to another server you can do it with the following commands:-

Step 1 : create the archive

tar -zcvf archive-name.tar.gz source-directory-name

Where, zcvf stands for

  • -z : Compress archive using gzip program in Linux or Unix
  • -c : Create archive on Linux
  • -v : Verbose i.e display progress while creating archive
  • -f : Archive File name

Step 2 : Transfer the archive using SCP

to copy a syntax of the SCP command is as follows:-

scp <source> <destination>

so To copy a file from a local to a remote system run the following command:-

scp archive-name.tar.gz user@server:/remote/directory/

You can extract the archive on the remote server using the following command:-

tar -xvf archive-name.tar.gz

to extract archive to specific directory use this command

tar -xvf archive-name.tar.gz -C /destination-path

Leave a Comment

Your email address will not be published. Required fields are marked *