![](/img/trans.png)
[英]Windows Batch script to SFTP files to remote location and then move them up a directory once finished
[英]Batch script to move files from a local directory to a particular ftp location
當前,我有一個批處理腳本,用於備份數據庫並將備份文件存儲在特定的本地目錄中,例如C:\\ Backups \\ backup-30-07-2011.bak(備份文件將使用當前日期創建)..
現在,我需要一個BATCH腳本將僅在當前日期創建的備份文件移動到FTP位置。 因此,我的批處理腳本必須:(1)使用其用戶名和密碼連接到ftp站點(2)將當前日期的文件移動到指定的ftp位置。
謝謝..
有關ftp的更多信息,請參見: http ://www.nsftools.com/tips/MSFTP.htm批處理腳本的示例,該腳本可制作備份副本:
@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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.