Solved

Check that file has been transfered completely from UNIX using ftp

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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…
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.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

809 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