Web Hosting Talk


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Need a zip to ftp script
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.

 
Thread Tools Search this Thread Display Modes
  #1  
Old 10-02-2008, 01:10 AM
amex amex is offline
View Beta Profile
Community Guide
 
Join Date: Jun 2006
Location: Amex & Amex
Posts: 1,273
Need a zip to ftp script

I'm looking for a shell script that will take a directory, zip it up, ftp it over to another server and then delete the local zip.

Anyone have such a script?

Thanks,

__________________
Looking for a real host? Companies who care: KnownHost, MediaLayer, WiredTree

Reply With Quote
Sponsored Links
  #2  
Old 10-02-2008, 01:24 AM
tuxg tuxg is offline
View Beta Profile
WHT Addict
 
Join Date: Sep 2007
Location: Vijayawada
Posts: 113
It is very easy to write one.
Do you want a .zip file or .tar.gz?
Is it okay to have the ftp user password
mentioned in that script?

__________________
Stable | Secure | Reliable
# Linux, Unix hosting only #


Reply With Quote
  #3  
Old 10-02-2008, 02:00 AM
amex amex is offline
View Beta Profile
Community Guide
 
Join Date: Jun 2006
Location: Amex & Amex
Posts: 1,273
Quote:
Originally Posted by tuxg View Post
It is very easy to write one.
Do you want a .zip file or .tar.gz?
Is it okay to have the ftp user password
mentioned in that script?
Either zip or tar is fine. I would prefer FTP password not to be in script - anyway to combat that?

__________________
Looking for a real host? Companies who care: KnownHost, MediaLayer, WiredTree

Reply With Quote
Sponsored Links
  #4  
Old 10-02-2008, 10:24 AM
tuxg tuxg is offline
View Beta Profile
WHT Addict
 
Join Date: Sep 2007
Location: Vijayawada
Posts: 113
Hi,

To create a tar.gz of /home, you can use the command:
tar -zcvf home.tar.gz /home

If you dont want the ftp password to be shown, you can try the .netrc method.
Pls check the security implications first.

Reference: http://www.inlumineconsulting.com:80...pting.ftp.html

__________________
Stable | Secure | Reliable
# Linux, Unix hosting only #


Reply With Quote
  #5  
Old 10-02-2008, 12:58 PM
justsurge justsurge is offline
View Beta Profile
WHT Addict
 
Join Date: Jun 2003
Posts: 117
hi, this is not a problem, you get get a pro, inexpensivly.

1 - i tar a file then gzip it vi command line.
2 - to zip directory, * zip -r namedir.zip /directoryname * most servers have zip installed, to check type * zip -help * & remove asterisks
3 - you can get & write a perl script to execute via command line.
4 - you can put anything you need in the script - and the password can get parsed via form input, the script does not need the password inside.
check php.net ftp functions, it's not hard
5 - add this to a perl script to zip a dir than place ftp functions.
print `zip -r nameforzip.zip ./dirname`
good luck, eliot

__________________
pentiume.com
Computer Services, Repairs and Emergency services, Home computers, programming, & everything IT related!



Last edited by justsurge; 10-02-2008 at 12:59 PM. Reason: grammer
Reply With Quote
  #6  
Old 10-02-2008, 01:05 PM
Exia Exia is offline
View Beta Profile
Junior Guru Wannabe
 
Join Date: Sep 2008
Location: UK!
Posts: 37
Just quickly writing up a full script for you, will edit this post when done.

Reply With Quote
  #7  
Old 10-02-2008, 01:33 PM
Exia Exia is offline
View Beta Profile
Junior Guru Wannabe
 
Join Date: Sep 2008
Location: UK!
Posts: 37
And done. See below.

Code:
Instructions
Call the script with the following.

./amex_backup ARCHIVE.TAR /LOCAL/FOLDER/TO/BACKUP REMOTE_FOLDER/TO/PUT/FILES FTP.DOMAIN.COM FTP_USERNAME FTP_PASSWORD

Script
#!/bin/bash
# Check Arguments
if [ $# != 6 ]; then
        echo "Usage: ./amex_backup ARCHIVE.TAR /FOLDER/TO/BACKUP FOLDER/TO/PUT/FILES FTP.DOMAIN.COM FTP_USERNAME FTP_PASSWORD"
        exit 0
fi
# Create Archive
echo "Attempting to create archive."
tar -cf $1 $2
echo "Archive successfuly created."
# FTP The Files
echo "Attempting to FTP files."
# FTP Commands
ftp -un $4 <<EOF
quote USER $5
quote PASS $6

binary
cd $3
put $1
quit
EOF
echo "FTP completed."
# Delete Temporary Directory
echo "Cleaning temporary archive."
rm -rf $1
# Done
echo "All done!"
Tested this a moment ago and it worked fine.

Reply With Quote
  #8  
Old 10-02-2008, 02:46 PM
markfrompf markfrompf is offline
View Beta Profile
Junior Guru
 
Join Date: Feb 2006
Location: Los Angeles
Posts: 226
Nice! Will test in just a sec.

EDIT: Yep, works great!

__________________
PhireFast - Web hosting and domain solutions since 2004
Backups every 4 hours via R1Soft, 24/7 support, Not a reseller, Entirely in the USA


Last edited by markfrompf; 10-02-2008 at 02:53 PM.
Reply With Quote
  #9  
Old 10-02-2008, 02:58 PM
amex amex is offline
View Beta Profile
Community Guide
 
Join Date: Jun 2006
Location: Amex & Amex
Posts: 1,273
Great thanks so much Exia. I forgot to ask if any one knew how to easily have this same script email you with the results....

__________________
Looking for a real host? Companies who care: KnownHost, MediaLayer, WiredTree

Reply With Quote
  #10  
Old 10-02-2008, 05:02 PM
Exia Exia is offline
View Beta Profile
Junior Guru Wannabe
 
Join Date: Sep 2008
Location: UK!
Posts: 37
Add this to the end of the script. Create the message_success.txt file somewhere, CHMOD it to 0777 and leave it blank.

Code:
SUBJECT="SSH Backup Results"
EMAIL="you@domain.com"
EMAILMSG="/path/to/message_success.txt"
echo "The directory $2 was archived to $1 and successfully uploaded to $4 to the directory $3 - yay!"> $EMAILMSG
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMSG

Reply With Quote
  #11  
Old 10-04-2008, 12:54 AM
tuxg tuxg is offline
View Beta Profile
WHT Addict
 
Join Date: Sep 2007
Location: Vijayawada
Posts: 113
OP doesnt want the ftp user password to be specified in the script, as i recall.
Can that be achieved by modifying this script? Specifying ftp password at the
command line is not a good idea AFAIK.

__________________
Stable | Secure | Reliable
# Linux, Unix hosting only #


Reply With Quote
  #12  
Old 10-04-2008, 07:44 AM
Exia Exia is offline
View Beta Profile
Junior Guru Wannabe
 
Join Date: Sep 2008
Location: UK!
Posts: 37
The OP didn't want the password specified in the script, which is what I provided.

Hard-coding the password in, is a bad idea, and a security risk. There are zero issues with specifying it at the command line, it's the same as entering a password into a GUI FTP client.

Can I ask why you think specifying the password at the command line is not a good idea?

If you -want- the password to be hardcoded in, simply replace "quote PASS $6" with "quote PASS yourpassword". I personally think that is a security risk, however.

Edit: If you want to use .tar.gz as opposed to .tar, simply replace tar -cf with tar -czf.

__________________
Exia Studios
Competent systems administration, development and hosting; premium service at a great price. Advice available.

Blog: Coming soon. | Email: sales@exiastudios.com | PIN: 2557B0C2 | Twitter: http://twitter.com/exiastudios

Reply With Quote
  #13  
Old 10-04-2008, 08:24 AM
tuxg tuxg is offline
View Beta Profile
WHT Addict
 
Join Date: Sep 2007
Location: Vijayawada
Posts: 113
Quote:
Originally Posted by Exia View Post
The OP didn't want the password specified in the script, which is what I provided.
Can I ask why you think specifying the password at the command line is not a good idea?
Hi Exia,

Password passed to the script as a command line argument is visible in process list when viewed using ps command. There is a way to limit a user to see only his/her processes, but that is not how we normally setup the hosting servers. If this is not a problem, then your solution is just right for this task.

Thank you,
tuxg

__________________
Stable | Secure | Reliable
# Linux, Unix hosting only #


Reply With Quote
  #14  
Old 10-04-2008, 08:37 AM
Exia Exia is offline
View Beta Profile
Junior Guru Wannabe
 
Join Date: Sep 2008
Location: UK!
Posts: 37
Quote:
Originally Posted by tuxg View Post
Hi Exia,

Password passed to the script as a command line argument is visible in process list when viewed using ps command. There is a way to limit a user to see only his/her processes, but that is not how we normally setup the hosting servers. If this is not a problem, then your solution is just right for this task.

Thank you,
tuxg
I would presume that a person would adequately secure their server that such delicate processes could not be seen by normal users.

__________________
Exia Studios
Competent systems administration, development and hosting; premium service at a great price. Advice available.

Blog: Coming soon. | Email: sales@exiastudios.com | PIN: 2557B0C2 | Twitter: http://twitter.com/exiastudios

Reply With Quote
  #15  
Old 10-04-2008, 08:43 AM
Exia Exia is offline
View Beta Profile
Junior Guru Wannabe
 
Join Date: Sep 2008
Location: UK!
Posts: 37
Here a script which accepts read input at the command line.

Create a file called backup, copy the contents - "chmod a+x backup" and then run ./backup.

Code:
#!/bin/bash
# Create Archive
echo "Archive To Create (NAME.tar.gz): "
read archivename
echo "Folder To Backup (sample_folder/): "
read folderbackup
echo "Attempting to create archive."
tar -czf $archivename $folderbackup
echo "Archive successfuly created."
# Get FTP Details
echo "FTP Domain (ftp.domain.com): "
read ftpdomain
echo "FTP Username: "
read ftpusername
echo "FTP Password: "
read ftppassword
echo "Folder To Put Files (e.g: public_html): "
read folderput
# FTP The Files
echo "Attempting to FTP files."
# FTP Commands
ftp -un $ftpdomain <<EOF
quote USER $ftpusername
quote PASS $ftppassword

binary
cd $folderput
put $archivename
quit
EOF
echo "FTP completed."
# Delete Temporary Archive
echo "Cleaning temporary archive."
rm -rf $archivename
# Done
echo "All done!"

__________________
Exia Studios
Competent systems administration, development and hosting; premium service at a great price. Advice available.

Blog: Coming soon. | Email: sales@exiastudios.com | PIN: 2557B0C2 | Twitter: http://twitter.com/exiastudios

Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement: