Solved

Validating ftp transfer from Unix Server

Posted on 2007-04-02
16
555 Views
Last Modified: 2013-12-20
I need to script the following task and place it in a cron;
I need to ftp two data files from our Unix Server to a common ftp file server. Once the file transfer is complete, I must send a header or flag file that tells a remote process on the ftp server tthat the transfer is complete otherwise I need to send a mailx out that indicates the transfer failed.
What would be the best way to determine if my transfer was complete. My first inclination is to compare file sizes between my local unix file and the remote ftp server file but am not clear on how to do that. I am unable to remotely connect to the ftp server with anything other than ftp. (ie. rsh ssh...)  Any help would be appreciated.
0
Comment
Question by:GeekMan
  • 7
  • 3
  • 2
16 Comments
 
LVL 38

Expert Comment

by:yuzh
ID: 18841108
why not using rsyn + ssh to do the job, it is easier and secure. it can perform the validation on fly.

more infor about rsync:
http://rsync.samba.org/

If you still want to  plain text file, the best you can do is you
use script to ftp login to your server, run ls -al command inside session and redirct  the output to a file, then the files size in the file against the file size you have download.
0
 

Author Comment

by:GeekMan
ID: 18842708
redirecting results in a zero byte local (unix) file that is of no value.
0
 

Author Comment

by:GeekMan
ID: 18846286
rsync or ssh....Unfortunately, I have no control over the technology used on the remote server. I have suggested these but so far ftp is the only thing we have available currently
0
 
LVL 84

Accepted Solution

by:
ozo earned 125 total points
ID: 18847112
Are you saying that
ls -al > file
creates a zero byte file?
even if the directory was empty it should have listed . and ..
If it llists the two data files, then you can use it as the  header or flag file that a a remote process can read to compare file sizes
0
 
LVL 38

Assisted Solution

by:yuzh
yuzh earned 125 total points
ID: 18847986
How did you redirect the out put, here's an example script
to get the filelist.txt:

# !/bin/ksh
USER=$1
PASSWD=$2
FTPSERVER=myserver
 
{
ftp -n  $FTPSERVER <<EOF
user $USER $PASSWD
lcd /path-to/myfiledir
ls -al
quit
EOF
# Make sure that there is no WHITE space before EOF
}> /path-to/filelist.txt

exit

the output is in /path-to/filelist.txt
then check filelist.txt
0
 
LVL 84

Expert Comment

by:ozo
ID: 18848688
was this supposed to run on the machine the files are coming from, or on the machine tho files are going to?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 38

Expert Comment

by:yuzh
ID: 18848740
I assume that you are runing the script in your locat machine to get the file list in the FTP server, and use the file list to compare the file
size you have download.
0
 

Author Comment

by:GeekMan
ID: 18853679
This is what I have so far. When I tee the output into my log file I get nothing. If I use the brackets { } as you suggested above, my script misinterprets the ftp code...(some of the code deals with alias package locations...disregard that.)

#!/usr/bin/ksh
if [[ -z $PKG ]];then . ~/.profile -q;fi

case ${PKG_LOC} in
      plf)      EDMS_AREA=west;;
      cin)      EDMS_AREA=east;;
esac

export EDMS_AREA
export psn_file='edm_psn_'${EDMS_AREA}
export xfm_file='edm_xfm_'${EDMS_AREA}
export psn_hdr='edm_psn_'${EDMS_AREA}
export xfm_hdr='edm_xfm_'${EDMS_AREA}

filelist=${psn_file}' '${xfm_file}
cd ${CES_HOME}/edm_exports

if SvcPkg -q;then
      print "Accessing Export Directory...\n"
      chmod 775 *.txt
      # first loop is psn file, 2nd loop is xfm file..
      for file in $filelist; do
            export fout=$file'_out.txt'
            export fhdr=$file'_hdr.txt'
            export lfsize=`wc -c ${fout} | cut -d" " -f1`
            print "Begin ${fout} File Transfer at:" $(date)

`ftp -inv ftpfile.cinergy.com <<-END_FTP
user LOGINNAME PASSWORD
ascii
prompt off
cd /ces/edm/${EDMS_AREA}
delete ${fout}
delete ${fhdr}
put ${fout}
size ${fout}
bye
END_FTP` | tee transfer.log

            export rfsize=`grep 213 transfer.log | cut -d" " -f2`
            if [[ ${lfsize} -eq ${rfsize} ]];
            then

ftp -inv ftpfile.cinergy.com <<-END_FTP1
user LOGINNAME PASSWORD
ascii
cd /ces/edm/${EDMS_AREA}
put ${fhdr}
bye
END_FTP1
            else
                  print ${fout}" file sizes did not match.."
            fi            
      done
else
      echo "Svc Package is not located on this node, this script will now exit."
      exit
fi      

# Removed loginname and password by yuzh {Page Editor}
0
 

Author Comment

by:GeekMan
ID: 18853848
(Community Support)..Please delete this question.
0
 

Author Comment

by:GeekMan
ID: 18876683
Vee_Mod, what I'd really like is an edit button that I can use to edit the posts that I author. Seems like you offered that in earlier versions..??
The bottom line is that I don't want the username and password shared in my 4:41pm post on this question...... whatever we have to do to accomplish this. If it mean deleteing the question then yes, let's delete it. If you have other options then please exercise them.....As a user I have none. (except to have never posted it to begin with!)

Thank you..
0
 

Author Comment

by:GeekMan
ID: 18878783
Thank you Vee_Mod... Mission accomplished....
0
 

Author Comment

by:GeekMan
ID: 18889042
yuzh,
Thanks...I transgressed the unwritten law...I know, I should have my head nailed to a table by one of the Piranha brothers.......!
It had been a long day....i was tired....I hit the submit button and then realizes.."Oh $#&%%.!!!."

Thanks again....
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
conditional code and condition difference 9 65
fizzArray  challenge 1 47
tripleUp challenge 7 67
MarkLogic 1 49
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…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

758 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

21 Experts available now in Live!

Get 1:1 Help Now