Hi,
I have written the following FTP script to get the multiple files from remote server to local server. My problem is that 'mget *' is not working in the script. I also tried with 'mget .txt', 'mget *.' etc. without any success. It do not copy any file to local server. In the script, Prompt is set off. However, when I try doing it manually, it works. Don't know, where the problem lies. My code is like,
$LOGIN=user
$FTPPASS=password
mkdir ftp`date '+%Y%m%d'`
cd ftp`date '+%Y%m%d'`
`ftp -vin <<- END_INPUT > $LOG/ftp_files.log 2>&1
open $DEVICE
user $LOGIN $FTPPASS
cd $PICKUP
mget *.txt
quit
END_INPUT`
Your ftp log files might have the information,
have you looked into that ?
you should have used "prompt" command before executing"mget" command
Hi,
can you try this code and let me know
this is working fine , i checked it
HOME1=/home/sri
echo " 1"
ftp -n server_ip << END_INPUT > /tmp/ftp_files.log 2>&1
user username password
cd $HOME1
prompt
mget *.txt
bye
END_INPUT
The op had obtained the same effect
having the
-i option
in ftp
Thanks a lot Srikanthus2002. I did as you mentioned and it's working fine when I try to FTP files in a directory "ftp`date '+%Y%m%d'`" on local server. But, when I try to ftp the same files to one more directory "ftp_verify`date '+%Y%m%d'`" on the local server using 'lcd' command, it do not copy anything there. Actually, to check wether files are FTP'ed correctly on local server, I need to use a verification logic in my script. And to do that I copy files from remote server in 2 different directories on local server and then compare them using 'diff' command in the script. Then after verification I delete the verification directory "ftp_verify`date '+%Y%m%d'`". Can you please explain, why it's not copying files in "ftp_verify`date '+%Y%m%d'`" directory? My scripts is like:
#!/bin/ksh
HOME1=/home/sri
echo " 1"
cd /home
mkdir ftp`date '+%Y%m%d'`
mkdir ftp_verify`date '+%Y%m%d'`
cd ftp`date '+%Y%m%d'`
ftp -n server_ip << END_INPUT > /tmp/ftp_files.log 2>&1
user username password
cd $HOME1
prompt
mget *.txt # copies files correctly
lcd /tmp/ftp_verify`date '+%Y%m%d'`
mget *.txt # Do not copy anything
bye
END_INPUT
cd /home
diff -w ftp`date '+%Y%m%d'` ftp_verify`date '+%Y%m%d'` > /dev/null
if [ $? -ne 0 ]
then
echo "Error: Files are not successfully FTP'd"
mailx -r user@vrfai030.private.annonymous.com -s \'"Files FTP failed'" user@annonymous.com < /tmp/ftp_fail.msg
exit 1
rm -r ftp_verify`date '+%Y%m%d'`
fi
exit 0
HOME1=/home/sri
mkdir /tmp/test
ftp -n server_ip << END_INPUT > /tmp/ftp_files.log 2>&1
user username password
asc
cd $HOME1
prompt
mget *.txt
lcd /tmp/test
mget *.txt
bye
END_INPUT
I tried with above code it works perfectly.
I can get the files in current directory (/home/sri) and /tmp/test directory as well.
just see your code....
you have created "ftp_verify" folder in /home directory and you tried to execute the lcd command with /tmp/ftp_verity.
still any issue pls show the o/p of "/tmp/ftp_files.lop" file.
Cheers..
srikanth
Thanks again Srikanthus2002. I modified the script as below and now it's working fine. I am able to copy multiple files in 2 seperate time stamped directories. Now, the problem lies in getting a mail after successful/failed FTP. I do not get any mail messege, even after files are copied properly.
#!/bin/ksh
HOME1=/home/sri
echo " 1"
cd /home/temp
mkdir ftp`date '+%Y%m%d'`
mkdir ftp_verify`date '+%Y%m%d'`
ftp -n server_ip << END_INPUT > /tmp/ftp_files.log 2>&1
user username password
cd $HOME1
prompt
lcd /home/tmp/ftp`date '+%Y%m%d'`
mget *.txt # copies files correctly
lcd /home/tmp/ftp_verify`date '+%Y%m%d'`
mget *.txt # copies files correctly
bye
END_INPUT
diff -w ftp`date '+%Y%m%d'` ftp_verify`date '+%Y%m%d'` > /dev/null
if [ $? -ne 0 ]
then
echo "Error: Files are not successfully FTP'd"
mailx -r user@server.private.xyz.com -s \'"Files FTP failed'" annonymous@xyz.com < /tmp/ftp_fail.msg
exit 1
rm -r ftp_verify`date '+%Y%m%d'`
mailx -r user@server.private.xyz.com -s \'"Files FTP successful'" annonymous@xyz.com < /tmp/ftp_succ.msg
fi
exit 0
<ModeratorHat>
berlin_germany,
pls do use vB Codes when posting to ease the readibility and proper formating.
</ModeratorHat>
It looks like you are missing an "else".
if [ $? -ne 0 ]
then
echo "Error: Files are not successfully FTP'd"
mailx -r user@server.private.xyz.com -s \'"Files FTP failed'" annonymous@xyz.com < /tmp/ftp_fail.msg
exit 1
else
rm -r ftp_verify`date '+%Y%m%d'`
mailx -r user@server.private.xyz.com -s \'"Files FTP successful'" annonymous@xyz.com < /tmp/ftp_succ.msg
fi
Your code would currently exit on an error, and do nothing on success.
Even after using if....then....else....fi in my code I am not getting any mail messege. I think, somehow "mailx -s" in above script is not working. I don't know, why? Because the same mail command is successful in the script, when I use ftp steps like,
`ftp -vin <<- END_INPUT > tmp/ftp_files.log 2>&1
.....
......
bye
END_INPUT`
But, using this the problem is that mget *.txt, mput *txt is not working. It only works for a single file transfer like, put, get etc. Can anybody please suggest a way to do that?