
10-02-2008, 01:10 AM
|
|
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
|

10-02-2008, 01:24 AM
|
|
|
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 #
|

10-02-2008, 02:00 AM
|
|
View Beta Profile
Community Guide
|
|
Join Date: Jun 2006
Location: Amex & Amex
Posts: 1,273
|
|
Quote:
Originally Posted by tuxg
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
|

10-02-2008, 10:24 AM
|
|
|
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 #
|

10-02-2008, 12:58 PM
|
|
|
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
|

10-02-2008, 01:05 PM
|
|
|
Just quickly writing up a full script for you, will edit this post when done.
|

10-02-2008, 01:33 PM
|
|
|
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.
|

10-02-2008, 02:46 PM
|
|
|
Nice! Will test in just a sec.
EDIT: Yep, works great!
Last edited by markfrompf; 10-02-2008 at 02:53 PM.
|

10-02-2008, 02:58 PM
|
|
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
|

10-02-2008, 05:02 PM
|
|
|
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
|

10-04-2008, 12:54 AM
|
|
|
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 #
|

10-04-2008, 07:44 AM
|
|
|
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.
|

10-04-2008, 08:24 AM
|
|
|
Quote:
Originally Posted by Exia
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 #
|

10-04-2008, 08:37 AM
|
|
|
Quote:
Originally Posted by tuxg
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. 
|

10-04-2008, 08:43 AM
|
|
|
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!"
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
| 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
HTML code is Off
|
|
|
|
|