Solved

Check that file has been transfered completely from UNIX using ftp

Posted on 2004-09-28
5
380 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Named range not carried over 10 65
Define unique primary key 9 95
matchUp  challenge 6 68
Excel file not created as expected 7 79
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

807 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