简体   繁体   中英

Batch script to move files from a local directory to a particular ftp location

Currently I have a batch script which backups my database and store the backup file in a particular local directory, for eg say, C:\\Backups\\backup-30-07-2011.bak (the backup files will be created with the current date)..

Now, I need a BATCH script to move ONLY the backup files which are created on the current date to a FTP location. Hence my batch script must: (1) Connect to a ftp site with its username and password (2) Move the file of current date to the specified ftp location.. can anyone help me on this batch script.

Thanks..

More info about ftp here: http://www.nsftools.com/tips/MSFTP.htm Example of batchscript, which makes copy of backup:

@echo off
    :: Set filename and path
    :: %date:.=-% mean replace dots '.' to '-' in the variable's value  (31.07.2011)
    :: More info: set /?
    set "fileName=backup-%date:.=-%.bak"
    :: There mustn't be slash in end. "C:\Backups\" is wrong, "C:\Backups" is right
    set "filePath=C:\Backups"
    set "ftpFilePath=somepath"

    :: there must be ftp's IP & port
    set "ftpIP=127.0.0.1"
    set "ftpPort=21"

    :: replace with your own username & password
    set "username=username"
    set "password=password"

    :: Write commands in file
    :: Open server
    echo o %ftpIP% %ftpPort%>ftpcmds
    :: Say your name & password. If you have no password - just do not change   these lines
    echo %username%>>ftpcmds
    echo %password%>>ftpcmds
    :: We send binary data, yep?
    echo binary>>ftpcmds
    :: Change ftp path
    echo cd %ftpFilePath%>>ftpcmds
    :: Change local path
    echo lcd "%filePath%">>ftpcmds
    :: Yeah, we can send file
    echo send %fileName%>>ftpcmds
    :: Bye = disconnect + quit
    echo bye>>ftpcmds

    :: Run ftp-client. More info: ftp --help
    :: Delete '>nul' if you want see output of ftp
    ftp -s:ftpcmds>nul
exit /b

If you want you can add command to delete original file (put it before 'exit /b'):

del /s/q %filePath%\%fileName%>nul

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM