Automatic FTP script


 
Thread Tools Search this Thread
Operating Systems SCO Automatic FTP script
# 1  
Old 06-02-2009
Question Automatic FTP script

We are using SCO OS 5.05 server and we are doing a manual ftp to another SCO OS 5.05 server to backup our database.
We are using the Bourne shell.
We would like to automate the ftp backup of our database instead of doing it manually.
It would be nice to run a script.
Also would there be anyway to hide the ftp password?
Any tips or help would be appreciated.
Please advise and thanks.
# 2  
Old 06-02-2009
Here is a simple simple ftp script you can follow: Not much luck on encrypting the password so you can not read it though.

Code:
 
#! /usr/bin/ksh

HOST=remote.host.name
USER=whoever
PASSWD=whatever

exec 4>&1
ftp -nv >&4 2>&4 |&

print -p open $HOST
print -p user $USER $PASSWD
print -p cd directory
print -p binary
print -p put tar.gz
print -p bye

wait
exit 0

# 3  
Old 06-02-2009
That isn't working at all.
Please advise.
Thanks
# 4  
Old 06-02-2009
You could store the password in a file encrypted by crypt(1) get your script to decrypt it as it uses it, not very secure but it would hide the password from the casual observer.

I've used ftp with an input file to give the commands before, e.g.:
Code:
$ cat cmdfile.template
open _FTPSERVER_
user _USER_ _PASSWORD_
cd directory
binary
put tar.gz
bye
$

And then a script like this:
Code:
HOST=remote.host.name
USER=whoever
PASSWD=whatever

sed -e 's/_FTPSERVER_/'${HOST}'/' -e 's/_USER_/'${USER}'/' -e 's/_PASSWORD_/'${PASSWD}'/' cmdfile.template > cmdfile
ftp < cmdfile

If you wanted to hide the password then encrypt it into a file using crypt, e.g.:
Code:
$ echo passwdofchoice > clear
$ echo keyofchoice > key.file
$ crypt `cat key.file` < clear > password.crypt
$ rm clear

Changing key to be the decryption key and password to ones of your choice.

The in the above script "PASSWD=whatever" would change to:
Code:
KEY=`cat key.file`
PASSWD=`crypt ${KEY} < password.crypt`

The filenames could be made more obscure and as I said the whole thing is not secure but it would hide things a bit...

Using scp to transfer files via SSH with passwordless SSH would be preferable and more secure if your ftp server is also running sshd.

Last edited by TonyFullerMalv; 06-02-2009 at 07:20 PM..
# 5  
Old 06-02-2009
For FTP passwords, try a .netrc file in $HOME for the FTP user with permissions 600 owned by root.
Code:
man .netrc

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Automatic counter script

Hello, I am having trouble calculating some numbers and I was hoping someone could help me solve this. I have one file with 1 column and what I'm trying to do is add up the lines until a certain value is reach, then jump to where it last finished counting and continue. so for ex: if I... (27 Replies)
Discussion started by: verse123
27 Replies

2. Shell Programming and Scripting

automatic FTP failed

I have automated ftp for different scripts. every script uses different login and passwords for different server. it reads the username and password from netrc. there is 1 particular script that is failing. this script is failing in FTP step. i have checked the logs it says login failed. but... (5 Replies)
Discussion started by: dazdseg
5 Replies

3. Shell Programming and Scripting

Automatic FTP-Download | not files older then x days

Hey Guys, i need to download files from a ftp-server that not older than $VAR (x) days eg for seven days ./script 7 or two weeks ./script 14 all files from the last 14 days will download but how i can explain "ftp" this? sorry for my strange english :/ (2 Replies)
Discussion started by: tetex
2 Replies

4. Shell Programming and Scripting

Automatic FTP

Hi I am looking for automatic FTP script from UNIX to UNIX servers. I have two problems that anyone may help: 1- The directory where the files have to be FTPed is varied, where it is identified by the date of today (YYYYMMDD) 2- the files come every 15 minutes and named by the time with form... (2 Replies)
Discussion started by: akhadoor
2 Replies

5. AIX

.netrc and Automatic ftp problem

Guy's We have two AIX servers Server1 and Server2 and we have created user1 in Server1 and Server2 ... and .netrc file was confiured under /home/user1 with the below line machine server2 login user1 password abc1234567 -rw------- 1 user1 staff 159 Sep 28 2004 .netrc ... (7 Replies)
Discussion started by: ITHelper
7 Replies

6. UNIX for Advanced & Expert Users

Automatic script

Hi, is it possible to automatically run a script (bash) when an event occurs? I mean, let's say that I (or one of my users) plug in a flash memory (USB) ... is it possible to run a script every time I do this action (let's say to log user, date and other infos on a file)? Thanks! Bye... (5 Replies)
Discussion started by: TShirt
5 Replies

7. Shell Programming and Scripting

Automatic FTP Script from windows to unix machine

Hi i need to FTP files from windows to unix(sun) machine using script. what are the scripts commands i need to use to transfer files Thanks (2 Replies)
Discussion started by: bmkreddy
2 Replies

8. Shell Programming and Scripting

Is it possible..when ftp session disconnect and it can automatic run again?

Hi, Is is possible when ftp script disconnect by remote server and it can restart to tranfer (such as restart in 10 mins, etc)? Please help!!!! (1 Reply)
Discussion started by: happyv
1 Replies

9. Shell Programming and Scripting

Automatic ftp job

I'm slowly (very slowly) learning csh and the UNIX underpinnings of Mac OS X so please bear with me. I want to be able to ftp a file to my personal webspace at work. I can do this by manually going in and doing ftp host.domain.com user: password: cd /folder put myfile etc.. I'd like... (4 Replies)
Discussion started by: DumDum
4 Replies

10. UNIX for Advanced & Expert Users

Automatic FTP

Hi, We have a requirement to transfer(FTP) files created in a particular directory (In Solaris) to NT machine. Also this process neeeds to be automated. I belive a command MAIL in UNIX could be used to find new files created in a directory, but this just sends the file list to the logged user.... (5 Replies)
Discussion started by: shyamrk
5 Replies
Login or Register to Ask a Question