Solved

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

Posted on 2001-07-08
1
457 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Folder Comparison 12 55
Detect CR LF to each line 12 174
VBA "SendKeys" Syntax for Multiple Keystrokes 7 125
I could not set window to top 4 40
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.

685 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