Upload files to a FTP site via batch script

http://www.howtogeek.com/50359/upload-files-to-an-ftp-site-via-a-batch-script/


Original Script: 

 
 @ECHO OFF
ECHO Upload to FTP
ECHO Written by: Jason Faulkner
ECHO SysadminGeek.com
ECHO.
ECHO.

REM Usage:
REM UploadToFTP [/L] FileToUpload
REM
REM Required Parameters:
REM    FileToUpload
REM        The file or file containing the list of files to be uploaded.
REM
REM Optional Parameters:
REM    /L    When supplied, the FileToUpload is read as a list of files to be uploaded.
REM        A list of files should be a plain text file which has a single file on each line.
REM        Files listed in this file must specify the full path and be quoted where appropropriate.

SETLOCAL EnableExtensions

REM Connection information:
SET Server=
SET UserName=
SET Password=


REM ---- Do not modify anything below this line ----

SET Commands="%TEMP%\SendToFTP_commands.txt"

REM FTP user name and password. No spaces after either.
ECHO %UserName%> %Commands%
ECHO %Password%>> %Commands%

REM FTP transfer settings.
ECHO binary >> %Commands%

IF /I {%1}=={/L} (
    REM Add file(s) to the list to be FTP'ed.
    FOR /F "usebackq tokens=*" %%I IN ("%~dpnx2") DO ECHO put %%I >> %Commands%
) ELSE (
    ECHO put "%~dpnx1" >> %Commands%
)

REM Close the FTP connection.
ECHO close  >> %Commands%
ECHO bye    >> %Commands%

REM Perform the FTP.
FTP -d -i -s:%Commands% %Server%

ECHO.
ECHO.

REM Clean up.
IF EXIST %Commands% DEL %Commands%

ENDLOCAL


/*********************   Modified script *************************/
/* Modified to provide fixed username/password and variable server IP 
to be passed on command line as first parameter and after that the file/ 
fileList to be ftp'd */

@ECHO OFF
ECHO FTP Upload Script

ECHO Written by: Jason Faulkner
ECHO SysadminGeek.com
ECHO.
ECHO.


REM Usage:
REM FTPScript serverIP [/L] FileToUpload
REM
REM Required Parameters:
REM serverIP
REM     The IP of FTP site; Username/password is hardcoded
REM
REM    FileToUpload
REM        The file or file containing the list of files to be uploaded.
REM
REM Optional Parameters:
REM    /L    When supplied, the FileToUpload is read as a list of files to be uploaded.
REM        A list of files should be a plain text file which has a single file on each line.
REM        Files listed in this file must specify the full path and be quoted where appropropriate.

SETLOCAL EnableExtensions

REM Connection information:
SET Server=%1
SET UserName=ftpuser
SET Password=ftppassword

SET Commands="%TEMP%\SendToFTP_commands.txt"
CD "D:\LIU_BACKUP\master"
REM FTP user name and password. No spaces after either.
ECHO %UserName%> %Commands%
ECHO %Password%>> %Commands%

REM FTP transfer settings.
ECHO binary >> %Commands%

IF /I {%2}=={/L} (
    REM Add file(s) to the list to be FTP'ed.
    FOR /F "usebackq tokens=*" %%I IN ("%~dpnx3") DO ECHO put %%I >> %Commands%
) ELSE (
    ECHO put "%~dpnx2" >> %Commands%
)

REM Close the FTP connection.
ECHO close  >> %Commands%
ECHO bye    >> %Commands%

REM Perform the FTP.
FTP -d -i -s:%Commands% %Server%

ECHO.
ECHO.

REM Clean up.
IF EXIST %Commands% DEL %Commands%

ENDLOCAL

Comments

Popular posts from this blog

Morning Quotes

QCalendarWidget CSS Stylesheeting

Selecting new phone plan