Auto FTP Scripts

From time to time, I would need to transfer large amount of files using FTP. I doesn’t like to do it manually.
And always let the scheduler/cron handle the file transfer automatically.

This is the batch script for Windows platform.

@echo off
set HOST=
set FTPUSER=
set FTPPASSWORD= set LOCALDIR=D:\local\path\

set /p FOLDER=[Enter Folder Name]
mkdir %LOCALDIR%\%FOLDER%
cd %LOCALDIR%\%FOLDER%
echo.

set /p SOURCE=[Enter Source Path]

echo user %FTPUSER% > autoftp.dat
echo %FTPPASSWORD% >> autoftp.dat
echo bin >> autoftp.dat
echo prompt off >> autoftp.dat
echo cd %SOURCE% >> autoftp.dat
echo mget * >> autoftp.dat
echo quit >> autoftp.dat

ftp -n -s:autoftp.dat %HOST%
del autoftp.dat


If you’re working on Linux, here is the script on Linux machine.

#!/usr/bin/ksh

HOST=
FTPUSER=
FTPPASSWORD=

echo "Enter Local Path:"
read LOCALPATH
LOCALPATH=`echo $LOCALPATH|tr -s '[:lower:]' '[:upper:]'`

echo "\Enter Source Path:"
read SOURCEPATH

mkdir $LOCALPATH
cd $LOCALPATH

ftp -n -v $HOST < < EOT ascii user $FTPUSER $FTPPASSWORD bin hash prompt off cd $SOURCEPATH mget * bye EOT

I’m looking for powershell script to do file transfer.
Anyone can share the powershell ftp script?

what to learn more on Shell script? This is one of the best book I even have: Mastering Unix Shell Scripting.

Posted in Shell Script Tagged with:

Leave a Reply