Solved

Check that file has been transfered completely from UNIX using ftp

Posted on 2004-09-28
5
342 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
  • 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 20

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 20

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
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.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

757 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

23 Experts available now in Live!

Get 1:1 Help Now