-   Linux - Newbie (
-   -   Shell Script for FTP and gzip (

venkimuck 04-05-2010 04:00 PM

Shell Script for FTP and gzip
I want to be able to write a shell script for downloading files (only *.tar extension) from multiple folders (the sub folder's names may vary) in a FTP site and be able to untar them and then gzip them and then move them to the real folder. Any help appreciated.

naman.jandial 04-05-2010 04:37 PM

If I am not wrong, what you want is:

1.) Download a tar file from an ftp site.
2.) Untar them
3.) Tar them a again with gzip and save them to a particular location.

Though I am new to Linux but will still try. Please do post, if I was rigt or wrong in my approach, this will help to understand the concept better.


tar -xvf filename.tar
for NAME in $(tar -tvf filename.tar)
tar -C /mydirectory -zcvf newfilename.tar $NAME

I hope this works, if it doesn't and you get the proper code, please do let me know.


naman.jandial 04-05-2010 04:46 PM

Or you can also do this:


tar -xvf filename.tar > downloaded_tar_files
for NAME in $(cat downloaded_tar_files)
tar -C /mydirectory -zcvf newfilename.tar $NAME

venkimuck 04-05-2010 04:47 PM

Thanks for trying to answer my question.

The ftp site has login and pwd (not annonymous login)

Also, I do not know the file name or number of files. I want to be able to find out and download all the *.tar files existing in a directory structure (that too does not have the name constant).

Once I untar the files, they are with .Z extension (compressed files). I have to uncompress them using gzip -d <file name>.

naman.jandial 04-05-2010 05:36 PM

Try this then:


enter password when prompted:
ls *.tar.gz > filenames
for NAME in $(cat filenames)
mkdir $NAME
tar -C $NAME -zxvf $NAME.tar.gz
tar -C $NAME -zcvf newfilename.tar.gz $NAME/*

GOD I hope it works, got a bit confused, while formulating it. LOL :D

All times are GMT -5. The time now is 07:40 AM.