?
Solved

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

Posted on 2001-07-08
1
Medium Priority
?
463 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 8

Accepted Solution

by:
mnashadka earned 240 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

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

770 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