Solved

Exit out of FTP session if target file is locked for writing

Posted on 2001-07-08
1
456 Views
Last Modified: 2013-12-26
I have a script that will regularily FTP to a directory and download the latest file. Sometimes the file will be busy being written and the FTP transfer will fail.

How to detect this event so I can retry the same file? I'll have the desired filename in a variable. I'll be writing a log of all successful transfers.

Current ftp script:

ftp whatever.com <<EOT
cd files
ls
quit
EOT

The above is called by this script:

#/bin/sh
export file_list=`./ftp-whatever-list.sh`
export last_file
for file_entry in $file_list; do
last_file=$file_entry
done
ftp whatever.com <<EOT
cd images
get $last_file
quit
EOT
echo $last_file >> down_files.log


Thanks,

Roger
0
Comment
Question by:dsitech
1 Comment
 
LVL 8

Accepted Solution

by:
mnashadka earned 60 total points
ID: 6263425
Roger, I think that the easiest thing for you to do would be to put the ftp into a function (assuming you're using a ksh or bash script), and get the print statements into a variable, which could then be checked for the search string:

#!/bin/sh

#Move the ftp into a function
function ftp_file
{
  ftp whatever.com <<EOT
  cd images
  get $1
  quit
EOT
}

export file_list=`./ftp-whatever-list.sh`
export last_file
for file_entry in $file_list; do
last_file=$file_entry
done

#Read the output of ftp into a variable
message=$( ftp_file $last_file )
#Check $message for whatever error message you are looking for

echo $last_file >> down_files.log
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Perl Awk Need Help 3 128
tripleUp challenge 7 86
Bartender label printing - switch on and off graphics 3 54
moto 4g phone enable finger print 4 26
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question