File not found handling in ftp script

Thread Tools Search this Thread
# 1  
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:
ftp -in server<<EOF
user username pwd
cd $tgtdir
mget  Filepattern

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

cd $localpath
ls Filepattern

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

cnt=`ls filepattern|wc -l`

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

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.

# 2  
Why not capture ftp's output to see what files it retrieved?

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

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.

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Science: Gadgets
Difficulty: Easy
The communication protocol NFC stands for Near-Field Control.
True or False?

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. UNIX for Dummies Questions & Answers

File Not found - Bash script

I'm facing issues in executing the bash script of mine. This script will pick the latest file received and connects SFTP server and files is placed on this remote server. Error message Enter password: "File movement" sftp> cd Test sftp> put Test_File_201309.txt File "Test_File_201309.txt"... (6 Replies)
Discussion started by: parpaa
6 Replies

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

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

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

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

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

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

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

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

Featured Tech Videos