Error in scripting ftp


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Error in scripting ftp
# 8  
Old 06-08-2005
The problem is that ftp is not well suited for batch use.

IMHO there are two possible options you have: instead of directly feeding the answers to ftp create a .netrc file and put the filenames, hostname, etc. there. Only then call ftp <hostname> and ftp will proceed from there. The .netrc file could be created by the script prior to the call of ftp.

The other (IMHO more elegant) solution is to use rcp (or its securified pendant scp) instead of ftp. rcp comes in two variations, kerberized and not kerberized, so be careful what you use. Additionally I'd like to recommend scp since it communication can't be traced. (The same is true for ssh as a replacement for telnet/rlogin.) The drawback is you have to install the system once and exchange keys between the machines every once in a while.

Hope this helps

bakunin
# 9  
Old 06-08-2005
Revised srcript

OK. I have revised the script using the "co-process" technique I got from this forum. I tried this one on our test
environment and it work on multiple files. My questions are
1. Using the exec 4>&1, will this not affect other parts of the script that calls this script?
2. This sub script is called from multiple scripts that runs every hour (to download ORD file to the other system (WMS).
3. Is this code OK to use? I am new in Unix scripting and not sure if it is ok......

Thanks a lot!

#!/bin/ksh
# =============================================================================================
# Script name : ftpcheck.ksh
# Description : This script will be called from release.ksh and wmsupld.ksh and other
# WMS script to ftp ORD file from ERP to WMS and then check if
# the ftp was successfull or not. Also, check if the header count of ORD
# file (HD record) matches with the total file count (wc -l)
#==============================================================================================
. /glo71sw/pro4bin/crondevl716
DIRSCRIPT=$PRODATA/scripts
cd $PRODATA
ORDDOWNLD=`ls ORD????.DLD`
# use test data....
ORDDOWNLD='ORD8705.DLD ORD8706.DLD ORD8707.DLD'
export ORDDOWNLD
echo $ORDDOWNLD

# ftp information
HOST_FTP=host
USER_FTP=admin
PASSWD_FTP=pass

exec 4>&1
ftp -nv >&4 2>&4 |&

print -p open $HOST_FTP
print -p user $USER_FTP $PASSWD_FTP
print -p ascii

for i in $ORDDOWNLD
do
# transfer ORD files one by one......
print -p put $i
print -p get $i J$i
done
print -p bye
wait

# Verify if ORD files processed are OK.

for i in $ORDDOWNLD
do

# after getting the file, make sure header count is correct.
TOT_CNT=`cat J$i | wc -l`
TOT_HD=`cat J$i | grep "HD" | cut -c17-25`
# Compare total lines with total count in HD record
echo "J$i : Total Rec Count = $TOT_CNT Total HD count = $TOT_HD" >> jgo.log
if [ $TOT_CNT -eq $TOT_HD ]
then
echo "J$i has equal record count and HD count" | elm -s"Record check - J$i
" email
else
echo "J$i has incorrect HD count" | elm -s"Incorrect HD count - J$i" email
fi

# Compare if the HD transferred is the same.....
diff -h X$i J$i > J$i.out

# "-s" checks if the file is existing and size is greater than 0. So
# a true status would mean there are differences between the files...

if [ -s J$i.out ]
then
cat J$i.out | elm -s"WMS file - $i - NOT EQUAL" email
else
cat J$i.out | elm -s"WMS file - $i - EQUAL" email
fi
rm J$i.out
done
# ================enf of script ftpcheck.ksh===========================
# 10  
Old 06-08-2005
It will not affect the calling script. Not sure what you mean by ok to use. I wrote the script you copied and placed it in the public domain. So it's free to use if that's what you mean.
# 11  
Old 06-08-2005
Thanks Perderabo!

What I meant about my code, if it is ok, is, if I coded it correctly. Smilie or there is a better way of coding it. A friend of mine suggested to use perl but if this code is ok, why use perl (i am not familiar with perl Smilie )
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

FTP scripting issue

I dont have enough bits to post in emergency, but I have an urgent FTP issue. A client of ours wants us to pull files from his server onto our server at which point we can process it. I ask a friend what to do, but I was just give the things to do, not how to do it. I havent written a Unix... (4 Replies)
Discussion started by: MJCreations
4 Replies

2. Shell Programming and Scripting

Scripting with FTP Process

Hi Guys, Good day ULF! I have a general "auto-ftp" code which looks something like this: #!/bin/sh cd $1 ftp -v -n $2 << EOF user $3 $4 prompt cd $5 bin mput $6 quit EOF This works pretty well, but I'm thinking of how can I make a code by maybe including on this code, for... (5 Replies)
Discussion started by: rymnd_12345
5 Replies

3. Shell Programming and Scripting

Need FTP scripting

Hi, Please can you tell me the script to transfer file from server A to Server B (1 Reply)
Discussion started by: e1994264
1 Replies

4. Shell Programming and Scripting

FTP scripting Help

Hi, I'm trying to do an FTP script that will read from a list of files and send only the files in that list. Would this work? Does anyone have anything simpler. ftp -nv <<EOF open server user username password get $(nawk -F_ -f bbb.awk Filelisting.txt) EOF (5 Replies)
Discussion started by: bbbngowc
5 Replies

5. Shell Programming and Scripting

Shell scripting - FTP

Can some one help with script to track ftp logins on AIX server.. (1 Reply)
Discussion started by: ddk2oo5
1 Replies

6. Shell Programming and Scripting

Ftp scripting question

Hi guys, I'm trying to create an ftp script that will read in a value from input, then search for files with the input value, and then ftp the files.. So far I've got my read answer set up, and it'll ls -lrt out my files with the value read answer var I given it... My question is, what... (14 Replies)
Discussion started by: Jazmania
14 Replies

7. Shell Programming and Scripting

FTP scripting

Hello, I'm sure this is an easy one for you UNIX pros. I would like to create and and automated an FTP process. The script should do this: 1. Log into a remote system 2. change to a specified directory 3. copy local files to the remote system 4. quit ftp 5. wait until the next schedule ... (7 Replies)
Discussion started by: bbbngowc
7 Replies

8. Answers to Frequently Asked Questions

Automate FTP / Scripting FTP Transfers

One of our most frequent questions is how to automate ftp transfers. There are several approaches. Since I'm writing this post, we will start with my favorite technique. :) In Automated FTP task I present a simple example of my ksh co-process technique. And note that later in this thread I... (0 Replies)
Discussion started by: Perderabo
0 Replies

9. Shell Programming and Scripting

scripting a ftp process

I am trying to automate a process in one of two ways: 1) ftp .txt files from a unix server to a Windows 2000 server. I want to do this in a script. Can I supply the login and password to the Windows server inside the script? 2) I tried this and failed: sftp .txt files from the unix server to... (2 Replies)
Discussion started by: gbernard
2 Replies

10. UNIX for Dummies Questions & Answers

Telnet FTP scripting

Hi quick question from a unix newbie Working on a project to get me using unix, the point of this project is to find a printer on the network check for jobs in the printer if the printer has no jobs do nothing if the printer has jobs then check the status for errors and e-mail the user. This... (2 Replies)
Discussion started by: w33man
2 Replies
Login or Register to Ask a Question