• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 431
  • Last Modified:

Check that file has been transfered completely from UNIX using ftp

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
DCfromDisplay
Asked:
DCfromDisplay
  • 2
  • 2
1 Solution
 
brettmjohnsonCommented:
If your ftp server supports rename:

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


0
 
DCfromDisplayAuthor Commented:
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
 
tfewsterCommented:
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
 
DCfromDisplayAuthor Commented:
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
 
tfewsterCommented:
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now