Solved

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

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Different colored text in ComboBox without Subclassing 8 44
Define unique primary key 9 81
twoTwo  challenge 35 86
mapBully challenge 6 88
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now