FTP Scripts for UNIX and Windows


Here are example FTP scripts to get a file from an FTP server.

UNIX:
With this script, pass the ftp server hostname, user ID, password and file name with the command. If the script's name is myftpscript.ksh here is how you should use this script:

myftpscript.ksh ftp_server user pass file_name

#!/bin/ksh
HOST=$1
USER=$2
PASSWD=$3
FILE=$4


# Change to working directory
cd /ftp_working_directory


#Delete existing file


if [ -f ${FILE} ];
then
rm ${FILE}
fi


#Download file from ftp server


ftp -vn $HOST <<END_FTP > /ftp_working_directory/ftplog 2>&1
quote USER $USER
quote PASS $PASSWD
ascii
get $FILE
bye
END_FTP
exit 0

Windows:
Again, pass the ftp server hostname, user ID, password and file name with the command. If the script's name is myftpscript.cmd here is how you should use this script:

myftpscript.cmd ftp_server user pass file_name

@ECHO OFF


set PATH=C:\ftp_working_directory;%PATH%
pushd "C:\ftp_working_directory"


if not exist %4 GOTO FILETRANS
del /q %4


:FILETRANS
echo open %1 > ftprfromserv.ftp
echo user %2 %3 >> ftprfromserv.ftp
echo debug >> ftprfromserv.ftp
echo pwd >> ftprfromserv.ftp
echo ascii >> ftprfromserv.ftp
echo get %4 >> ftprfromserv.ftp
echo quit >> ftprfromserv.ftp


ftp -n -i -s:ftprfromserv.ftp > ftplog.txt 2>&1


exit 0

Comments

Popular posts from this blog

OS/DB Migration - CMD. STR, TOC, EXT, R3load, DDLDBS.TPL and more

Fixing Inconsistent Table - Table activation fails due to inconsistency between DD and DB

301 Redirect Using SAP Web Dispatcher