Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FTP script

Status
Not open for further replies.

operadornine

IS-IT--Management
Jul 19, 2010
51
0
0
AR
Hi all,

I need help to create a script to connect to a ftp and a sftp
download a file an check in the download was completed correctly.

Thanks in advance.
 
What have you done so far? Please post code.

Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
mrn,
the code is simple
ftp x.x.x.x
user='x'
pass='x'

the problem is always is requesting me to put the user and password.

thanks
 
From my experience, I have found FTP to be very reliable, but difficult to verify if a transmission was successful. In my application I verify if a "put" command was successful by "get"ing the file back and comparing it to the original. That works well in most cases, but can be inefficient for large files of millions of records.

Here is a snippet of code I use from one of my scripts that calls ftp and and checks for errors:

check_ftp_rc() {
typeset ftp_log_filename="$1"

if [ ! -s "$ftp_log_filename" ]; then
return 2
else
[[ $(grep -i "unknown host" "$ftp_log_filename") != "" ]] && return 3
[[ $(grep -i "login failed" "$ftp_log_filename") != "" ]] && return 4
[[ $(grep -i "No such file" "$ftp_log_filename") != "" ]] && return 5
[[ $(grep -i "timed out" "$ftp_log_filename") != "" ]] && return 6
[[ $(grep -i "Not connected" "$ftp_log_filename") != "" ]] && return 7
rc=$(grep "rc=" "$ftp_log_filename" | sed -e 's/^.*(rc=//' -e 's/)$//')
[ "$rc" != "" ] && return $rc
fi

return 0
} # check_ftp_rc()

ftp -inv $FTP_HOST <<EOD 1>>$ftp_log_filename 2>&1
user ${DOMAIN_NAME:+"$DOMAIN_NAME\\\\"}$FTP_USER_ID $FTP_USER_PW
`eval echo $REMOTE_CD_CMD`
pwd
$FTP_CMD
EOD

The ftp output is redirected to a log file ($fpt_log_filename) and a routine(check_ftp_rc) is called to check for certain error strings. If none are found a return code of 0 is returned.

I don't think there is an easy way to suppress prompting of the password with sftp as is the case with ftp.

I hope this helps you get started
 
I forgot to include the last 2 lines after the "EOD" line:

check_ftp_rc $ftp_log_filename
rc=$?
 
dkyrtata

do you have any scritp just to log in to a ftp server?

thanks
 
No I do not have any scripts that log into a server. I only need to connect with FTP. This means I can transfer files back and forth, and I can validate a userid/password with a mere connection.

I am not clear why you would want to login as opposed to connect to a server. What do you want to do when you log in?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top