File not found handling in ftp script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers File not found handling in ftp script
# 1  
Old 12-08-2011
File not found handling in ftp script

I have a pattern for filename to be searched.
I need to get the files from remote server Who are matching the file pattern.
And i need to exit with non zero return code for:

1)No files found matching that pattern

2)More than one files matching the name pattern.

If only one files is matching, then exit with zero return code.

Currently i am doing like in the below script:
Code:
ftp -in server<<EOF
user username pwd
cd $tgtdir
mget  Filepattern
quit
bye
EOF

if [ $? -ne 0 ]
then
echo "there are some issues in FTP"
fi

cd $localpath
ls Filepattern

if [ $? -eq 2 ]
then
echo "File not found"
exit 3
else
echo "File transfer success"
fi

cnt=`ls filepattern|wc -l`

if [ cnt -gt 1 ]
then
echo "More than one file"
exit 2
else
echo "Only one file"
exit 0
fi

But i dont think , the above is not the good approach and that may lead to ugly false negatives in some cases.

Please suggest me, how i can achieve this.

Thanks
# 2  
Old 12-08-2011
Why not capture ftp's output to see what files it retrieved?

Code:
ftp -in server >logfile 2>&1 <<EOF
user username pwd
cd $tgtdir
mget  Filepattern
quit
bye
EOF

How to process logfile depends on what its output actually is of course. FTP on my system probably doesn't look much like FTP on yours. Post a sample and we can help.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script FTP maintain error handling

Hi, I have ftp script like below How to insert an error handling, If the transfer failed then send mail to me. Actually, I just need the script to send an email if the FTP failed. How to put the email script within FTP script? Thank You Edy (5 Replies)
Discussion started by: edydsuranta
5 Replies

2. Solaris

FTP error handling - critical

Hi all, I have done google on the aforementioned subject. But didn't find any authentic way of checking 100% Successful FTP transaction. In my case I have critical backup of source code on daily basis. I have shell script which will: 1: "mput" backup files to remote server using FTP 2:... (8 Replies)
Discussion started by: viki250
8 Replies

3. Shell Programming and Scripting

Shell Script to monitor folder and upload found files via FTP

Hi everyone! I'm in a need of a shell script that search for all files in a folder, move all those files to a temp folder, and upload those files via FTP. When the file transfer via FTP completes successfully, the file is moved to a completed folder. In case any of those files fails, the file... (4 Replies)
Discussion started by: pulsorock
4 Replies

4. Shell Programming and Scripting

FTP File transfer - Exceptions handling

Hello All, How we can capture the FTP file transfer status. I would like do the exceptions handling for the FTP file transfer My code is something like this... ftp -nvi $FTP_SRVR |& print -p user $UID $PWD print -p cd mydir print -p put $FILE_NAME print -p close print -p bye ... (3 Replies)
Discussion started by: amazon
3 Replies

5. Linux

Handling "command not found" exception

hello friends, I am given a project to handle the command not found exception.I am using RED HAT 9. Generally, when we press a wrong command in the terminal: example :- " $cet " in place of " $cat ". Then we get this exception. But I need to give the output as the combinations that are possible... (5 Replies)
Discussion started by: nsharath
5 Replies

6. Shell Programming and Scripting

File handling in Script

Hi All, How can we handle file operation in scripts. I have written a script that run ok otherwise however the "Cat" operation leaves a process open on the box. Command is like cat "${LASTFILENAME}" | /usr/xpg4/bin/awk -F, '{do{if ($3 == "100" && $4 == "300" && $170 ~ /^abc/) { ... (2 Replies)
Discussion started by: raman1605
2 Replies

7. Shell Programming and Scripting

Handling ftp error

I have a script which connects to remote server and ftp the files It works fine, however if there is any failure in ftp connection can it be handled??? ftp log ftp session start time is: Thu Jun 19 00:00:02 BST 2008 Not connected. Not connected. Interactive mode off. Not connected.... (1 Reply)
Discussion started by: vivek_damodaran
1 Replies

8. Shell Programming and Scripting

Shell script file handling

Hi ! /bin/sh set logdir1 "logDir/local/logname" #write the filename into a file echo $logdir1 >> logname.txt how do i exec the above echo command (1 Reply)
Discussion started by: nathgopi214
1 Replies

9. 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

10. Shell Programming and Scripting

Continue Script when File Found

Hello All, I am trying to write a script that will only continue executing my script if a file exits. I know the directory of the file, so its just a matter of seeing if the file exists yet. If the file has not yet been created, I want the script to wait 10 minutes (600 seconds) and try again.... (7 Replies)
Discussion started by: Jose Miguel
7 Replies
Login or Register to Ask a Question