2

I'm trying to write bash script for file copying from local machine to FTP using lftp.

Problem is, when someone enter inaccessible path for mkdir or put, then lftp returns:

Access failed: 550 /: Device or resource busy

And my Bash script gets stuck and doesn't terminate.

How can I check if I am able to access resource before executing next commands?

Here is the relevant section of my code:

OUTPUT=`lftp -u $USER,$PASS -p $PORT $HOST <<HEREDOCUMENT
set ftp:ssl-allow no                                    
mkdir $FTP_DIR                                          
put $LOCAL_DIR/$LOCAL_FILE -o $FTP_DIR/$FTP_FILE        
bye                                                     
HEREDOCUMENT`                                           
0

As suggested in comments, you can prevent the process from getting stuck by using a timeout, for example:

OUTPUT=$(lftp -u $USER,$PASS -p $PORT $HOST <<EOF
set net:timeout 5
set net:max-retries 2
set net:reconnect-interval-base 5
set ftp:ssl-allow no                                    
mkdir $FTP_DIR                                          
put $LOCAL_DIR/$LOCAL_FILE -o $FTP_DIR/$FTP_FILE        
bye                                                     
EOF)

@Marki made an excellent suggestion in a comment:

larger FTP scripts you may use Perl or similar, which would allow you to perform explicit error handling after each command.

  • 1
    One may add that for larger FTP scripts you may use Perl or similar, which would allow you to perform explicit error handling after each command. – Marki Dec 27 '14 at 21:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.