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

Posted on 2001-07-08
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 <<EOT
cd files

The above is called by this script:

export file_list=`./`
export last_file
for file_entry in $file_list; do
ftp <<EOT
cd images
get $last_file
echo $last_file >> down_files.log


Question by:dsitech
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

Accepted Solution

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:


#Move the ftp into a function
function ftp_file
  ftp <<EOT
  cd images
  get $1

export file_list=`./`
export last_file
for file_entry in $file_list; do

#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

Featured Post

Industry Leaders: 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
Pressing cancel button with C# UI Automation 3 101
Line meaning 9 96
noX challenge 17 143
Updating statistics with error notification email in SQL server 4 126
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

739 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