Script for FTP proxy
Feb 6th, 2007 by robert
In one project when I was writing procedure for FTP-uploading I faced a very restrictive FTP proxy. All attempts to use standard libraries from apache did not succeed. Itried to connect with FAR manager and failed as well. Sysadmin confirmed that that none of ftp clients will work non-unanimously through FTP. So the only option was to write shell script that will be called from java code and perform FTP transfer. Here is what I've got:
CODE:
-
#!/bin/sh
-
-
FTP_HOST=$1
-
FTP_NAME=$2
-
FTP_PASS=$3
-
-
SRC_FILE=$4
-
DST_FILE=$5
-
-
PROXY_SERVER=192.168.1.1
-
-
TMPFILE=`mktemp /tmp/ftptrans_remotels.XXXXXXXXXX`
-
-
if [ "$5" = "" ] ; then
-
echo Ftp File Transfer via MAERSK proxy
-
echo
-
echo Usage:
-
echo ftptrans.sh [FTP_HOST] [FTP_NAME] [FTP_PASS] [SRC_FILE] [DST_FILE]
-
echo note that DST_FILE must be a file name without directories
-
exit
-
fi
-
-
echo "FTP TRANSFER to $FTP_NAME@$FTP_HOST identified by $FTP_PASS"
-
echo "tmp file is $TMPFILE"
-
-
ftp -n $PROXY_SERVER <<EOF
-
user $FTP_NAME@$FTP_HOST $FTP_PASS
-
binary
-
put $SRC_FILE $DST_FILE
-
ls . $TMPFILE
-
bye
-
EOF
-
-
cat $TMPFILE | if grep $DST_FILE ; then
-
echo Done
-
exit 0
-
else
-
echo Error
-
exit 1
-
fi
After upload we take list of remote files in temp file and check if our just uploaded file exists there. If not we raise an error that will be logged iin java code.