用于将文件从本地目录移动到特定ftp位置的批处理脚本

时间:2011-07-30 08:52:21

标签: batch-file

目前我有一个批处理脚本,用于备份我的数据库并将备份文件存储在特定的本地目录中,例如比如,C:\ Backups \ backup-30-07-2011.bak(将使用当前日期创建备份文件)..

现在,我需要一个BATCH脚本来仅将当前日期创建的备份文件移动到FTP位置。 因此我的批处理脚本必须: (1)使用其用户名和密码连接到ftp站点 (2)将当前日期的文件移动到指定的ftp位置。 任何人都可以帮我解决这个批处理脚本。

谢谢..

1 个答案:

答案 0 :(得分:1)

有关ftp的更多信息:http://www.nsftools.com/tips/MSFTP.htm batchscript的示例,它制作备份副本:

@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

如果需要,可以添加删除原始文件的命令(将其放在'exit / b'之前):

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