DEV Community

Cover image for Copy Files Compressed with Tar via ssh from and to a Linux Server
Konstantin Filtschew
Konstantin Filtschew

Posted on

Copy Files Compressed with Tar via ssh from and to a Linux Server

Copying files from a development machine or a server to another one may take up a lot of time, resources and traffic which dependent on the task may be more or less a problem. There are common Linux/Unix tools like scp and rsync to do the job, but they may be a wrong choice dependent on the task like:

  • copy a lot of small files (like node_modules) are big like text files or images in uncompressed formats like BMP or TIFF
  • have special attributes set, which you want to transport over the wire (like permissions or user/group IDs set)
  • files with encoding in names, which should be just transferred with errors

The most common Solution in both Directions

These are the most common combination to copy files using tar to compress and ssh for transport (using pipes) which may be suitable for most solutions.

Copy the folder data/ from current machine (development machine or current server) to remote server or system to folder /opt. The sever must support ssh and have tar installed, which is common for most Linux/Unix systems.

tar czf - data/ | ssh user@remoteserver "cd /opt && tar -xvzf - "
Enter fullscreen mode Exit fullscreen mode

Copy the folder data/ in /opt to current machine (development machine or current server) from remote server or system. The server must support ssh and have tar installed, which is common for most Linux/Unix systems.

ssh user@remoteserver "cd /opt && tar -cfz data/" | tar xfzv
Enter fullscreen mode Exit fullscreen mode

Deeper understanding

If you want to get a deeper understanding what all the parameters do, where to use them and which one you may need for which task, check the full article on my site: qameta.com.

Image of AssemblyAI

Automatic Speech Recognition with AssemblyAI

Experience near-human accuracy, low-latency performance, and advanced Speech AI capabilities with AssemblyAI's Speech-to-Text API. Sign up today and get $50 in API credit. No credit card required.

Try the API

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay