Page 1 of 1

unix ftp script

Posted: Tue Jan 25, 2005 11:31 am
by DSkkk
hi All
i need to automate the process of FTPing the source file from remote host to the local directory. i am writing the shell script to FTP the latest file from the remote directory. but the general ls -1t |tail -1command does not work in the ftp part. what is the command to pick the latest or last file when we do ls -1t ?
this is how my script looks
#!/bin/sh

#variables
#define local data dir
local_data_dir=.................

#remote dir and host properties
remote_dir=
remote_host=
user=
password=

clear

#define ftp host and user information
host=
userid=
password=

#ftp to DC and get the pgp file
echo Starting FTP
ftp -n $remote_host << END_FTP
user $user $password
cd toremotedir
put "ls -l" files.list
bye
END_FTP

echo FileName
#echo file $pgp_file recieved at $local_data_dir
echo

#get $remote_dir/$pgp_file $local_data_dir/$pgp_file
#change dir to loacl data dir
#cd $local_data_dir

#identify most recently generated pgp file
#pgp_file=`ls -tr *.pgp|tail -l`

#define decrypted filename w/ extension '.xml'
#xml_file=$pgp_file.xml

the ftp part in the script is not retirning the file.

thanks.

Posted: Tue Jan 25, 2005 1:51 pm
by ketfos
Hi,

Try this in your script before you do a put command.

x=`ls -t | head -1`
echo $x
put x

Ketfos

Posted: Tue Jan 25, 2005 4:02 pm
by kduke
You could use mget and mput to get multiple files. You need to turn off prompting with prompt command.

mget k*

Will get all files that start with a "k".