3

So here is what I have done already:

I have a file called abc.txt which contains list of files. I am using abc.txt to move those files to a folder, tar that folder and finally I download the tar to my local PC from my server, which is running GNU/Linux.

Here are the steps in list form:

  1. abc.txt
  2. abc.txt (listed files) -> folder
  3. Folder -> folder.tar
  4. folder.tar -> local PC.

If abc.txt contains 2 files, for example:

example1.css
example2.css

I need to download those files from abc.txt separately and directly to the local PC.

Since ftp or sftp need the file name to download it, how can I read that from abc.txt?

strugee
  • 14,723
  • 17
  • 73
  • 119
Mano
  • 279
  • 2
  • 6
  • 13

3 Answers3

5

If the file abc.txt contains the list of filenames relative from /path/to/base:

ssh user@server tar c -T /path/to/abc.txt -C /path/to/base | (cd /tmp; tar xv)

This creates a tarball on-the-fly, without actually saving it anywhere, pipe it to the local shell, extract, effectively copying the listed files.

EXTRA TIPS

If the file abc.txt contains the list of absolute paths:

ssh user@server tar c -T /path/to/abc.txt | (cd /tmp; tar xv)

If the file abc.txt is on your local system, not the remote:

ssh user@server tar c -T- < /path/to/abc.txt | (cd /tmp; tar xv)

To use gzip compression (using default level 6):

ssh -C user@server tar c -T /path/to/abc.txt | (cd /tmp; tar xv)

To use gzip compression level 9:

ssh user@server 'tar c -T /path/to/abc.txt | gzip -9' | (cd /tmp; tar zxv)
janos
  • 11,171
  • 3
  • 35
  • 53
1

Here is a simple script witch works with files containing spaces in the filename :

SAVEIFS=$IFS; IFS=$(echo -en "\n\b") ; for elt in `cat abc.txt` ; do scp $elt <YOUR_SFTP_CONNECTION> ; done ; IFS=$SAVEIFS
Slyx
  • 3,845
  • 2
  • 19
  • 25
  • Why treat backspace as a separator? (Yes, I know you read it somewhere, but I've never traced it back to its origin. It makes no sense.) You forgot to turn off globbing. Using `read` is more robust, see [How to loop over the lines of a file?](http://unix.stackexchange.com/q/7011). – Gilles 'SO- stop being evil' Dec 30 '13 at 22:57
0

I think the hub of your problem is how to extract the correct files from your list for your subsequent two logic paths.

egrep 'example1.css|example2.css' abc.txt

will give you all lines that match the exceptions, and

egrep -v 'example1.css|example2.css' abc.txt

will give you all lines that don't match the exceptions

X Tian
  • 10,413
  • 2
  • 33
  • 48