I would like to pipe an scp pull operation(sample without tar below) through tar, so that only one tar file is written for about 10 directories:

user@localhost:/home/user> scp -r remoteuser@remotehost:dir_to_transfer ./

I have directories on a remote machine that have about 10,000 small(~28k)files per directory to transfer. Due to file quotas, I don't have much free space to run the tar command on the remote host(remotehost). Due to firewall rules, I can only initiate the transfer from my local machine(localhost).

The sheer number of files makes the transfer very long.

I have found examples of how to do this when "pushing" the data, but would like to know how to do this when "pulling" the data.

Local machine info:

  • OS:OpenSuSe 13.2(x86_64)

  • bash 4.2.53(1)

  • OpenSSH_6.6.1p1, OpenSSL 1.0.1k-fips 8 Jan 2015

Remote machine info:

  • OS: CentOS release 5.11 (Final)
  • bash 3.2.25(1)
  • OpenSSH_4.3p2, OpenSSL 0.9.8e-fips-rhel5 01 Jul 2008

1 Answer 1


try from user@localhost

 > ssh -l remoteuser remotehost "tar cf - dir_to_transfert" > remote.tar


  • > is the prompt
  • ssh -l remoteuser remotehost connect you to remote host
  • "tar cf - dir_to_transfert" perform remote tarin to standard output
  • > remote.tar redirect ssh's output to localfile name remote.tar

this will work if you are allowed tar on remote host.

  • You have an extraneous ) character
    – Barmar
    Feb 15, 2015 at 6:04
  • @Barmar thank, my first intend was ( ssh ... ) > foo , but since local shell get > first.
    – Archemar
    Feb 15, 2015 at 9:32
  • Yeah,I had a feeling it was an edit like that
    – Barmar
    Feb 15, 2015 at 9:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .