Copy files over SSH: Difference between revisions
No edit summary |
No edit summary |
||
| Line 3: | Line 3: | ||
= Efficient File Transfer with Tar and SSH = | = Efficient File Transfer with Tar and SSH = | ||
Quickly transfer directories over SSH using tar. Great for migrations or backups. | |||
== | == Commands == | ||
<pre | '''Local to remote:''' | ||
<pre> | |||
tar cjf - /path/to/local/dir | ssh user@remote-host 'tar xjf - -C /path/to/remote/destination' | tar cjf - /path/to/local/dir | ssh user@remote-host 'tar xjf - -C /path/to/remote/destination' | ||
</pre> | |||
== | '''Remote to local:''' | ||
<pre> | |||
ssh user@remote-host "tar cjf - -C /path/to/remote/source ." | tar xjf - -C /path/to/local/destination | |||
</pre> | |||
== Notes == | |||
* Add <code>--exclude='pattern'</code> to skip files or directories. | |||
* Replace <code>j</code> with <code>z</code> (i.e., <code>czf</code>, <code>xzf</code>) to use gzip for faster, but less compressed, transfers. | |||
Revision as of 12:41, 31 July 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 - /path/to/local/dir | ssh user@remote-host 'tar xjf - -C /path/to/remote/destination'
Remote to local:
ssh user@remote-host "tar cjf - -C /path/to/remote/source ." | tar xjf - -C /path/to/local/destination
Notes
- Add
--exclude='pattern'to skip files or directories. - Replace
jwithz(i.e.,czf,xzf) to use gzip for faster, but less compressed, transfers.