FTP script - Need a little help here with it.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FTP script - Need a little help here with it.
# 1  
Old 09-09-2008
FTP script - Need a little help here with it.

Hi there all..

I have the following.
I have a FTP someware where raports are put on.
I have to FTP to it and get them in and than delete the remote
But all the time there are new files put in, so I dont want to delete after I copy, becouse than I can delete files that are not yet copyed.
And it is kinda sensetive information as in no body will be able to read it but it better not get deleted withoud getting a copy on this side.

I build this script, and well it is getting the files but it is not putting the files to the correct local dir. and I disabled the mdelete function for now, so I dont loose files, but I want to use that the same as the mget.

Code:
#!/usr/bin/ksh
#
 set -x 
 
## VARIABLES##
 
RNODE="192.168.10.30"
USER="*****"
PASSWD="********"
LOCALDIR="/glims/mgnt/mmpamm"
REMOTEDIR=""
DIRLISTFILE="${LOCALDIR}/${RNODE}.$(basename ${REMOTEDIR}).dirlist.out"
cat /dev/null > $DIRLISTFILE
 
HISTLOG=/glims/mgnt/mmpamm/logs/ftphist.log
FTPLOG=/glims/mgnt/mmpamm/logs/ftptrans.log
glimspad=/glims/mgnt/mmpamm
ERROR_FILE=/glims/mgnt/mmpamm/errorfile
HOSTNAME=`uname -n`
 
## DEFINE FUNCTIONS HERE ##
 
 
######### Check if there is an error file #########
function errorfile_check
{
 if test -r $ERROR_FILE
 then
  rm $ERROR_FILE
 fi
}
######### Ping check if host is avalible #########
function ping_check
{
 ping $RNODE -n 2 > $glimspad/pingctrl.txt
 PINGCTRL=`cat $glimspad/pingctrl.txt | wc -l`
}
######### ERROR report #########
function report_ERROR
{
 echo `date '+%d %b %H:%M:%S'` $RNODE NIET gevonden >> $HISTLOG 2>&1
 echo stop `date '+%d %b %H:%M:%S'` >> $HISTLOG 2>&1
 touch $ERROR_FILE
 echo `date '+%d %b %H:%M:%S'` "communicatie PC: $RNODE" >> $ERROR_FILE
 echo "Let op !!!!!" >> $ERROR_FILE
 echo ""  >> $ERROR_FILE
 echo "Fout tijdens overdracht PAMM" >> $ERROR_FILE
 exit
}
######### File check from host (FTP) #########
function file_check_host
{
 ftp -i -v -n 192.168.10.30 <<END_FTP
 user $USER $PASSWD
 nlist $REMOTEDIR $DIRLISTFILE
 bye
 
END_FTP
}
######### File Copy from host (FTP) #########
function file_copy_host
{
 ftp -i -v -n 192.168.10.30 <<END_FTP
 
 user $USER $PASSWD
 lcd $LOCALDIR
 cd $REMOTEDIR
 mget $DIRLISTFILE
 bye
 
END_FTP
}
######### File Remove from host (FTP) #########
function file_remove_host
{
 ftp -i -v -n $RNODE <<END_FTP
 
 user $USER $PASSWD
# mdelete 
 bye
 
END_FTP
}
 
## BEGINNING OF MAIN ##
 
 
errorfile_check
ping_check
 
if  pingctrl=7 
then
 file_check_host
sleep 5
 file_copy_host
sleep 5
 file_remove_host
fi
# End of script

# 2  
Old 09-09-2008
This is a script that I use to pull files from an FTP server and then delete them. I do two ftp's, the first one gets the files and the second one is built and the delete lines are created based on the files that I retrieved. I might give you and idea of how you could delete only the files you retrieved. Hope this helps.

Code:
ftp -in ftp.server.com <<End-Of-Session
user userid password
type ascii
cd outbound
lcd /lsf1/law/logan/OWENS/temp
mget *
quit
End-Of-Session
cat /lsf1/law/logan/OWENS/temp/* > /lsf1/law/logan/OWENS/OM810
if [[ -s /lsf1/law/logan/OWENS/OM810 ]]; then
   echo 'ftp -in ftp.server.com <<E-O-F' > /law1/lawson/logan/edi_bin/om810ftp
   echo 'user userid password' >> /law1/lawson/logan/edi_bin/om810ftp
   echo 'type ascii' >> /law1/lawson/logan/edi_bin/om810ftp
   echo 'cd outbound' >> /law1/lawson/logan/edi_bin/om810ftp
   cd /lsf1/law/logan/OWENS/temp/
   ls | while read filename
   do
     echo 'delete ' $filename >> /law1/lawson/logan/edi_bin/om810ftp
   done
   echo 'quit' >> /law1/lawson/logan/edi_bin/om810ftp
   echo 'E-O-F' >> /law1/lawson/logan/edi_bin/om810ftp
   . /law1/lawson/logan/edi_bin/om810ftp
   rm /lsf1/law/logan/OWENS/temp/*
   cp /lsf1/law/logan/OWENS/OM810 /lsf1/law/logan/edi_arch_inb/OM810.inb."$(date +%Y%m%d%H%M%S)"
else
    echo "File OM810 not found or is empty"
	return 12
fi
exit

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

configuration for ftp script in main script

Hi, I am new to shell scripting,and i was planning to write a script that will FTP files to destination folder. I was planning that All configuration should be done through a properties files. and finally the output should be Files are transferred I have developed a properties file named... (4 Replies)
Discussion started by: rahul125
4 Replies

2. Shell Programming and Scripting

Need help in ftp script

hello , I am working on a FTP script which navigates to specific directory and pulls the file Issue which i am facing :: ---------------------------- i) When there is a file it pulls the file , but when there is not file in the directory it fails in the same statement and it is not... (3 Replies)
Discussion started by: ranga27
3 Replies

3. Linux

Need SCP script equivalent to FTP script .

Hi, Currently i'm using the folllowing FTP acript and its working. echo "open $server" > ftp_file echo "user $user $password" >> ftp_file echo "cd $remote_dir" >> ftp_file echo "lcd $local_dir" >> ftp_file echo "put $file">> ftp_file echo "bye" >> ftp_file ftp -nv < ftp_file I've... (1 Reply)
Discussion started by: vickramshetty
1 Replies

4. Shell Programming and Scripting

Automated FTP script using .netrc to multiple FTP servers

Hi all, I'm using the following script to automated ftp files to 1 ftp servers host=192.168.0.1 /usr/bin/ftp -vi >> $bkplog 2>&1 <<ftp open $host bin cd ${directory} put $files quit ftp and the .netrc file contain machine 192.168.0.1 login abc... (4 Replies)
Discussion started by: varu0612
4 Replies

5. Shell Programming and Scripting

passing parameter to ftp script from output of another ftp

Hi, I have a ftp script which first gets all the file names and echo's the latest file. I'm using another ftp command sets to get the file name given by first ftp. The problem is the parameter is not accepted by second ftp. The error message i'm getting is > Rename Temp File calloc:ICMP... (5 Replies)
Discussion started by: ammu
5 Replies

6. Shell Programming and Scripting

ftp script not able to connect to ftp server.

I have the following ftp script to get files from a remote location. However, on running the script I find that I am not even able to connect to ftp server. I am able to connect to ftp server using other GUI ftp tools like WS_FTP using the same IP. IP used here is a dummy IP. What can go... (3 Replies)
Discussion started by: gram77
3 Replies

7. Shell Programming and Scripting

FTP script to FTP file to UNIX - Solaris

Hello, A couple of times per week, i receive emails notifications when files are available for processing. Currently i read these eamails with a java program and store the attachement on my C: drive and would now like to generate a PC script to send this file name up to UNIX-Solaris and... (3 Replies)
Discussion started by: bobk544
3 Replies

8. Shell Programming and Scripting

Need help - script for ftp..

I have my ftp script as below.. This is logging the messages into ftp.log file , But I want the same output(what ever messages are going into ftp.log) to be printed on the console too for the user to show the status.. Tried with "tee" .. unable to get the solution.. Can some one help me... (3 Replies)
Discussion started by: Srini75
3 Replies

9. UNIX for Dummies Questions & Answers

excuting a shell script within ftp script

Novice here... I need help with excuting a shell script on a flat file that I've transfered over from a Windows XP machine for manipulation through an auto FTP script... so that after it is transfers it excutes the shell script and then returns it back to XP machine... Any ideas... (2 Replies)
Discussion started by: Gerry405
2 Replies

10. Shell Programming and Scripting

FTP script in Unix shell script

Hello , I am trying to make a shell script (Unix) for a ftp connection to another server and to get a file. So I have no knowledge about ftp and my script must do automaticly the connection with the user and passwd. Can you help us about that... Christian... (2 Replies)
Discussion started by: steiner
2 Replies
Login or Register to Ask a Question