unix ftp script

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
DSkkk
Charter Member
Charter Member
Posts: 70
Joined: Fri Nov 05, 2004 1:10 pm

unix ftp script

Post 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.
g.kiran
ketfos
Participant
Posts: 562
Joined: Mon May 03, 2004 8:58 pm
Location: san francisco
Contact:

Post by ketfos »

Hi,

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

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

Ketfos
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post 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".
Mamu Kim
Post Reply