Copy files over SSH: Difference between revisions

From Jwiki
No edit summary
No edit summary
Line 9: Line 9:
'''Local to remote:'''
'''Local to remote:'''
<pre>
<pre>
tar cjf - /path/to/local/dir | ssh user@remote-host 'tar xjf - -C /path/to/remote/destination'
tar cjf - -C /path/to/local/ <source-dir> | ssh user@remote-host 'tar xjf - -C /path/to/remote/ <target-dir>'
</pre>
</pre>


'''Remote to local:'''
'''Remote to local:'''
<pre>
<pre>
ssh user@remote-host "tar cjf - -C /path/to/remote/source ." | tar xjf - -C /path/to/local/destination
ssh user@remote-host 'tar cjf - -C /path/to/remote/ <source-dir>' | tar xjf - -C /path/to/local/ <target-dir>
</pre>
</pre>



Revision as of 10:40, 1 August 2025


Efficient File Transfer with Tar and SSH

Quickly transfer directories over SSH using tar. Great for migrations or backups.

Commands

Local to remote:

tar cjf - -C /path/to/local/ <source-dir> | ssh user@remote-host 'tar xjf - -C /path/to/remote/ <target-dir>'

Remote to local:

ssh user@remote-host 'tar cjf - -C /path/to/remote/ <source-dir>' | tar xjf - -C /path/to/local/ <target-dir>

Notes

  • Add --exclude='pattern' to skip files or directories.
  • Replace j with z (i.e., czf, xzf) to use gzip for faster, but less compressed, transfers.