Solved

Check that file has been transfered completely from UNIX using ftp

Posted on 2004-09-28
5
397 Views
Last Modified: 2013-12-26
I am ftp'ing a file to a remote server using a unix.prog file scheduled through Oracle. I would like to know if the ftp process fails by receiving some type of email alert. I have hacked together a bit of code that I have found, but this does not fully address the issue. The current code returns successful as long as the ftp connection is made, but I need to know that the file has been uploaded complete. Is there a simple way to incoroporate this feature?

I very very little experience with Unix, so please be desciptive if possible.

Thanks in advance.

Here is some of my current code:

# Set some variables to be used in this script
UTL_DIR=/u03/log+out/APRD/tmp
SQL_DIR=$CUSTOM_TOP/sql
FNAME="some_data"
FNAME1="some_data.csv"

# Change Dir to UTL_FILE directory
cd $UTL_DIR
echo $UTL_DIR
ftp <<** 192.1.1.244
cd Testing_Directory
put $FNAME1
bye
**

if [ "$?" -ne 0 ]
then
  echo
  echo "FTP Failed to move $FNAME1"
  mailx -s"*** Some_Data Failed to Upload Properly ***" me@mycompany.com
  echo
else
  echo
  echo "FTP'd $FNAME1"
  mailx -s"The Some_Data upload was successful" me@mycompany.com
  echo
fi
0
Comment
Question by:DCfromDisplay
[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
  • 2
  • 2
5 Comments
 
LVL 23

Expert Comment

by:brettmjohnson
ID: 12171945
If your ftp server supports rename:

put $FNAME1 $FNAME1.tmp
rename $FNAME1.tmp $FNAME1


0
 

Author Comment

by:DCfromDisplay
ID: 12172373
The problem is not putting the file out on the server, the problem is ensuring that the file has been completely uploaded. If for some reason I make contact with the ftp server, but the file is no able to be uploaded, no error message is generated via the code above. The error would be present in UNIX, but as this will be an automated process, I will need an alert to be emailed to me regarding the failure.
0
 
LVL 21

Accepted Solution

by:
tfewster earned 125 total points
ID: 12173751
ftp returns ?$ = 0 if the ftp program executed successfully - But it _doesn't_ return the results of individual commands.  So you'll need to capture the output of the FTP session and grep the results out of that, e.g.

ftp -v <<** 192.1.1.244
cd Testing_Directory
put $FNAME1
bye
**  > /tmp/ftplog 2>&1

if [ "`grep 'Transfer complete' /tmp/ftplog`" ]
then
  echo
  echo "FTP'd $FNAME1"
  mailx -s"The Some_Data upload was successful" me@mycompany.com
else
  echo
  echo "FTP Failed to move $FNAME1"
  mailx -s"*** Some_Data Failed to Upload Properly ***" me@mycompany.com < /tmp/ftplog
fi
0
 

Author Comment

by:DCfromDisplay
ID: 12174508
I had just a little trouble with the code. I'm not sure why, but I changed it to:

(
echo ascii
echo passive
echo put $FNAME1
echo quit
) | ftp -v -i 192.1.1.244 > /tmp/ftplog 2>&1


It didn't seem to like the > /tmp/ftplog 2>&1 directly after the ** even when I type it in directly.

Many thanks!
0
 
LVL 21

Expert Comment

by:tfewster
ID: 12174553
It might be worth trying this format:
ftp -v > /tmp/ftplog 2>&1 <<** 192.1.1.244
cd Testing_Directory
put $FNAME1
bye
**  

- but I'm pleased to hear you got it working
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Get filename and folder into excel 7 87
CRON statement to run every 3 minutes except on Monday morning 12am to 2am 7 121
no14 challenge 14 76
EvenOdd challenge 10 159
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

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