@echo off goto SETDFTVAL ::Display help :DSPHELP echo =================================== echo SSIFTP (Simple System i FTP client) echo =================================== echo. echo Copyright (c) 2009 Rory Hewitt echo. echo rory.hewitt@gmail.com echo http://www.corisoft.com echo. echo Redistribution and use, with or without modification, is permitted echo provided that the following conditions are met: echo. echo 1. Redistributions must retain the above copyright notice, echo this list of conditions and the following disclaimer. echo. echo THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ''AS IS'' echo AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED echo TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A echo PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR echo OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, echo SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT echo LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF echo USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED echo AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT echo LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN echo ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE echo POSSIBILITY OF SUCH DAMAGE. echo ============================================================================= echo SSIFTP allows you to run FTP commands to copy objects, source members and IFS echo files to and from a System i (iSeries, AS/400). echo. echo You may pass parameters to SSIFTP in any order, by passing each parameter echo with an immediately preceding parameter flag, e.g.: echo. echo -t src -u john -p johnpass -m 192.168.0.1 -r qgpl -f qclsrc echo. echo Valid parameter flags are as follows: echo. echo -t FTP type ('src', 'obj' or 'ifs') echo -m Machine (System i) name or IP address echo -u User profile echo -p Password echo -w Disable PC firewall during FTP. Must be passed as 'Y' to disable firewall echo -x FTP command file containing further FTP commands echo -l Default local (PC) directory for PUT/GET echo -r Default System i directory/library for PUT/GET echo -f Default System i file for PUT/GET ('src' mode only) echo -s Save output (Y/N) echo /h Displays this help text and then quits echo. echo If you do not pass all required parameters, you will be prompted to echo enter values for them. In most cases, a default value will be echo displayed in parentheses following the prompt text, e.g. echo. echo "Enter System i library ('QGPL'):" echo. echo If you press Enter without entering a value, the default value echo will be used. echo. echo Before you use SSIFTP for the first time, you should set the default values for echo your System i. See the SETDFTVAL section below for the list of default values. echo. pause goto EXIT :: Set default values :SETDFTVAL :: Before using SSIFTP for the first time, you should change the values below to appropriate :: values for your System i. Values should be entered without quotes and with no space after :: the '=' sign, e.g.: set dftmachine=192.168.0.1 :: dftmachine: Specify the name or TCP/IP address of your System i set dftmachine=your-system-i :: dftuser/dftpassword: Specify the default System i user profile and password to use for FTP set dftuser=user-profile set dftpassword=password :: dftlcldir: Specify the default PC directory to use for PUT/GET. set dftlcldir=.. :: dftrmtdir: Specify the default System i directory for PUT/GET (IFS only) set dftrmtdir=/ :: dftrmtlib: Specify the default System i library for PUT/GET (OBJ/SRC only) set dftrmtlib=QGPL :: dftrmtfil: Specify the default System i file for PUT/GET (SRC only) set dftrmtfil=QTXTSRC :: Display as red text on a white background color fc :GETPARMS if "%1" == "" goto SETTYPE if "%1" == "-t" set ftptype=%2 if "%1" == "-u" set user=%2 if "%1" == "-p" set password=%2 if "%1" == "-m" set machine=%2 if "%1" == "-w" set firewall=%2 if "%1" == "-x" set ftpfile=%2 if "%1" == "-l" set lcldir=%2 if "%1" == "-r" set rmtdir=%2 if "%1" == "-f" set rmtfil=%2 if "%1" == "-s" set save=%2 if "%1" == "-h" goto DSPHELP if "%1" == "/h" goto DSPHELP if "%1" == "?" goto DSPHELP shift shift goto GETPARMS ::Set the FTP type :SETTYPE if "%ftptype%" == "" set /p ftptype=Enter FTP type (src, obj or ifs): if "%ftptype%" == "src" goto SETPARMS if "%ftptype%" == "obj" goto SETPARMS if "%ftptype%" == "ifs" goto SETPARMS if "%ftptype%" == "exit" goto EXIT goto SETTYPE :: Get the machine, user and password parameters if not passed :SETPARMS if "%machine%" == "" set /p machine=Enter machine name ('%dftmachine%'): if "%machine%" == "" set machine=%dftmachine% if "%user%" == "" set /p user=Enter user profile ('%dftuser%'): if "%user%" == "" set user=%dftuser% if "%password%" == "" set /p password=Enter password ('%dftpassword%'): if "%lcldir%" == "" set /p lcldir=Enter local directory ('%dftlcldir%'): if "%lcldir%" == "" set lcldir=%dftlcldir% :: Check if the firewall should be disabled if not "%firewall%" == "Y" goto BUILDSCRIPT echo disabling firewall... netsh firewall set opmode disable ::Build the first bits of the FTP script :BUILDSCRIPT > script.ftp type NUL >> script.ftp echo open %machine% >> script.ftp echo %user% >> script.ftp echo %password% >> script.ftp echo quote site namefmt 1 >> script.ftp echo lcd %lcldir% :: Check which type of FTP we're doing :CHECKTYPE if "%ftptype%" == "src" goto SRC if "%ftptype%" == "obj" goto OBJ if "%ftptype%" == "ifs" goto IFS :SRC :: When FTPing source members, we use ASCII (since it's text) set rmtlib=%rmtdir% if "%rmtlib%" == "" set /p rmtlib=Enter System i library ('%dftrmtlib%'): if "%rmtlib%" == "" set rmtlib=%dftrmtlib% if "%rmtfil%" == "" set /p rmtfil=Enter System i file ('%dftrmtfil%'): if "%rmtfil%" == "" set rmtfil=%dftrmtfil% >> script.ftp echo ascii >> script.ftp echo cd qsys.lib/%rmtlib%.lib/%rmtfil%.file goto FTP :OBJ :: When FTPing objects, we use BINARY (since it's an object) set rmtlib=%rmtdir% if "%rmtlib%" == "" set /p rmtlib=Enter System i library ('%dftrmtlib%'): if "%rmtlib%" == "" set rmtlib=%dftrmtlib% >> script.ftp echo bin >> script.ftp echo cd qsys.lib/%rmtlib%.lib goto FTP :IFS :: When FTPing IFS files, we use ASCII (since it's probably text) if "%rmtdir%" == "" set /p rmtdir=Enter System i directory ('%dftrmtdir%'): if "%rmtdir%" == "" set rmtdir=%dftrmtdir% >> script.ftp echo ascii >> script.ftp echo cd %rmtdir% goto FTP :FTP if not "%ftpfile%" == "" goto BATCH goto INTER :BATCH :: Append any additional commands from the external FTP commands file if not "%ftpfile%" == "" >> script.ftp type %ftpfile% :: Append QUIT so FTP session will stop >> script.ftp echo. >> script.ftp echo quit :: Start FTP in batch mode, outputting screen to log file ftp -s:script.ftp > log.ftp :: Delete the FTP log if not "%save%" == "Y" del log.ftp goto DELETE :INTER :: Start FTP in interactive mode ftp -s:script.ftp goto DELETE :DELETE :: Delete the FTP script if not "%save%" == "Y" del script.ftp :: Re-enable the firewall if it was disabled if "%firewall%" == "Y" goto ENABLE goto EXIT :EXIT exit :ENABLE @echo off echo. echo re-enabling firewall... netsh firewall set opmode enable goto EXIT