Zip and ftp script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Zip and ftp script?
# 15  
Old 07-25-2013
Quote:
Originally Posted by Corona688
quote it. I'm not 100% sure the FTP part will work.

Code:
function FTP_ZIP()
{
      zip_file=$1
      ftp -n remote_server <<FTP
         quote USER remote_username
         quote PASS remote_password
         prompt noprompt
         put "$zip_file"
         ls -l
         bye
FTP
}

for dir in *
do
        zip -r "$dir.zip" "$dir"
        FTP_ZIP "$dir.zip"
        rm "$dir.zip"
done

hi corona668
may be i am wrong but why do you think the FTP part wont work??
actually i am using the similar way for doing FTP to remote servers and it works fine. one drawback is that you will have to pass your password to the ftp in this way. if you do not want to hard code your username and password in the script, try using .netrc file.

---------- Post updated at 12:15 PM ---------- Previous update was at 08:35 AM ----------

sorry.. function word will not come in front of the function name

Code:
FTP_ZIP()
{
      zip_file=$1
      ftp -n remote_server <<FTP
         quote USER remote_username
         quote PASS remote_password
         prompt noprompt
         put "$zip_file"
         ls -l
         bye
FTP
}

for dir in *
do
        zip -r "$dir.zip" "$dir"
        FTP_ZIP "$dir.zip"
        rm "$dir.zip"
done

# 16  
Old 07-25-2013
Quote:
Originally Posted by Little
hi corona668
may be i am wrong but why do you think the FTP part wont work??
Because the quotes may confuse it.
# 17  
Old 07-26-2013
I just noticed when I try to unzip the zip files with windows explorer it says... the compressed zip file is invalid!

with windows winrar it says Unexpected end of archive!

but if I open the zip files with linux centos they are just fine

if I run zip -r name.zip name just from the command line the zip file works fine in windows?
# 18  
Old 07-26-2013
Try using a binary FTP. Add the command binary in the FTP deck something like this:-
Code:
ftp -inv $host <<-EOFTP >$LOGFILE
user userid password
binary
cd $target_dir
prompt
put "$zip_file"
quit
EOFTP

The default if probably ASCII, and that can corrupt a non-ASCII file in transit.



Robin
# 19  
Old 07-26-2013
Quote:
Originally Posted by rbatte1
Try using a binary FTP. Add the command binary in the FTP deck something like this:-
Code:
ftp -inv $host <<-EOFTP >$LOGFILE
user userid password
binary
cd $target_dir
prompt
put "$zip_file"
quit
EOFTP

The default if probably ASCII, and that can corrupt a non-ASCII file in transit.

Robin
adding binary did the trick, thanks Smilie

---------- Post updated at 06:09 AM ---------- Previous update was at 05:30 AM ----------

to take this script one step further.. how can I process more than one folder?

so I execute the script in the root directory with all the folders inside
eg.
folder1 has 100 folders inside
folder 2 has 100 folders inside
etc

so the script would create the folders with the same name on the ftp server and copy them in to the same folder?
resulting in a copy of my files but all zipped individually in there own folders.

currently I have to go in to each folder to execute the script.

I tried adding mkdir "$dir" cd "$dir" but its creating seperate folders for each individual zip file rather than just a folder with the same name with all the zip files inside.


thanks
# 20  
Old 07-26-2013
If you don't want to cd into it, don't. zip will still work, that's what the -r is for.
Code:
zip -r filename.zip foldername

# 21  
Old 07-26-2013
Quote:
Originally Posted by Corona688
If you don't want to cd into it, don't. zip will still work, that's what the -r is for.
Code:
zip -r filename.zip foldername

it doesnt work Smilie I spent hours trying.
for example I have the following folders

Code:
/home/fred/folder1/test1
/home/fred/folder1/test2
/home/fred/folder2/test1
/home/fred/folder2/test2

I want to end up with the following on the ftp server

Code:
/folder1/test1.zip
/folder1/test2.zip
/folder2/test1.zip
/folder2/test2.zip

so I am keeping the folder structure the same on both ftp and home pc but all folders on the ftp will be zipped

thanks

Last edited by Scott; 07-28-2013 at 05:47 AM.. Reason: Code tags
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Help with Zip and FTP Shell Script

I am trying to combine zip and ftp upload in one script but for some reason I can't get it to work. It zips properly but does not ftp, seems like it just ignores ftp. Any help would be greatly appreciated. Thanks! #!/bin/sh cd /home/user/test zip -r test.zip * FOLDER='/home/user/test'... (2 Replies)
Discussion started by: shimabuku
2 Replies

2. Shell Programming and Scripting

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (1 Reply)
Discussion started by: b.saipriyanka
1 Replies

3. UNIX for Beginners Questions & Answers

How can we Zip multiple files created on the same date into one single zip file.?

Hi all i am very new to shell scripting and need some help from you to learn 1)i have some log files that gets generated on daily basis example: i have abc_2017_01_30_1.log ,2017_01_30_2.log like wise so i want to zip this 4 logs which are created on same date into one zip folder. 2)Post zipping... (2 Replies)
Discussion started by: b.saipriyanka
2 Replies

4. Shell Programming and Scripting

Zip Multiple files to One .zip file in AIX system

Hi I have a requirement in unix shell where I need to zip multiple files on server to one single .zip file. I dont see zip command in AIX and gzip command not doing completely what I want. One I do .zip file, I should be able to unzip in my local Computer. Here is example what I want... (9 Replies)
Discussion started by: RAMA PULI
9 Replies

5. Shell Programming and Scripting

zip the folder and loaded to ftp

Hi , I am working on a script which will do the below things 1) It will checkout from the repository 2) then zip that checkout stuff 3) and put the zip folder to FTP server Here my question is I am able to checkout successfully through this coomand svn co... (2 Replies)
Discussion started by: rohit22hamirpur
2 Replies

6. UNIX for Dummies Questions & Answers

extract rar/zip files from pc DIRECTLY on xbox (FTP)

Hello I've an old xbox connected to Ubuntu 8.04 with an ethernet cable. I use gFTP to transfer files on xbox (through FTP). When I have to transfer a rar file, first of all I have to extract it on ubuntu, then on xbox. I would like to transfer rar files directly on xbox. Is it possible with... (4 Replies)
Discussion started by: paolobitta
4 Replies

7. UNIX for Dummies Questions & Answers

diff between TAR+zip+FTP and TAR+FTP

Huloo, whats diff between TAR+zip+FTP and TAR+FTP,can't we simpply FTP a file without Zipping it? TAR is simply for Archiving ,then why do we need to Zip it? :( (1 Reply)
Discussion started by: swarup2008
1 Replies

8. UNIX for Dummies Questions & Answers

unzip .zip file and list the files included in the .zip archive

Hello, I am trying to return the name of the resulting file from a .zip archive file using unix unzip command. unzip c07212007.cef7081.zip Archive: c07212007.cef7081.zip SecureZIP for z/OS by PKWARE inflating: CEP/CEM7080/PPVBILL/PASS/G0063V00 I used the following command to unzip in... (5 Replies)
Discussion started by: oracledev
5 Replies

9. Shell Programming and Scripting

ftp zip files corruption

Hi I have a zip file that I am ftping to another server. After I have ztped the file it is corrupt and cannot be opened by winzip. Can anyone throw any light on to why this would happen. I have no problems with sending the individual files, but when zipped into one file it becomes... (3 Replies)
Discussion started by: colesga
3 Replies

10. Shell Programming and Scripting

check if exists a .ZIP file and unzip it using ftp

hi this is my question i have my script what have to verify the existence of a .ZIP file in a extern server (using ftp). if there are .ZIP files, the idea is what the script "unzip" them in the specified folder. THE PROBLEM IS what the script doen´t unzip the .ZIP files, and besides, delete... (1 Reply)
Discussion started by: DebianJ
1 Replies
Login or Register to Ask a Question