<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[Latest posts for the topic "[Windows]如何定時自動備份整個網站目錄到遠端伺服器"]]></title>
		<link>https://forum.andowson.com/posts/list/15.page</link>
		<description><![CDATA[Latest messages posted in the topic "[Windows]如何定時自動備份整個網站目錄到遠端伺服器"]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ :!:設計理念 
<br>
1.先將要備份的目錄壓縮起來（節省傳輸時間） 
<br>
2.然後再ftp到遠端的伺服器去（建立日期目錄） 
<br>
3.定時自動執行（如每日凌晨三點） 
<br>
<br>
首先，3可用Windows附屬應用程式=&gt;系統工具=&gt;排定的工作來完成，我們最後設定即可。 
<br>
1和2則需要寫支DOS batch程式來完成，假設叫做remote_backup_web.bat。底下是該bat檔案的內容 
<br>
[code=bat] 
<br>
rem --------------------------------------------------------------------------- 
<br>
rem Backup web application to remote host 
<br>
rem 
<br>
rem $Id: remote_backup_web.bat 2007-02-07 21:24:43Z andowson $ 
<br>
rem --------------------------------------------------------------------------- 
<br>
<br>
@echo off 
<br>
rem Find out web server's IP address 
<br>
ipconfig | findstr "Address" &gt; ip1.txt 
<br>
for /f "tokens=1-2 delims=:" %%i in (ip1.txt) do echo %%j &gt; ip2.txt 
<br>
for /f "tokens=1-2 delims= " %%i in (ip2.txt) do (set ip=%%i) 
<br>
del ip1.txt 
<br>
del ip2.txt 
<br>
<br>
rem Get today's year, month, day 
<br>
for /f "tokens=1-3 delims=/ " %%a in ('date /t') do (set year=%%a&amp; set month=%%b&amp; set day=%%c) 
<br>
<br>
rem Modify the following line for your environment 
<br>
set TARGET=C:\Inetpub\wwwroot\demoweb 
<br>
set TARGETNAME=demoweb 
<br>
set BACKUPDIR=D:\backup 
<br>
set BACKUPFILE=%BACKUPDIR%\%year%\%TARGETNAME%_%ip%_%year%%month%%day%.zip 
<br>
set LOGFILE=%TARGETNAME%_backup.log 
<br>
<br>
echo. | date | findstr "現在日期" &gt;&gt; %LOGFILE% 
<br>
echo. | time | findstr "現在時間" &gt;&gt; %LOGFILE% 
<br>
<br>
rem Compress the target directory before ftp 
<br>
zip -r %BACKUPFILE% %TARGET%\* 
<br>
<br>
if not exist %BACKUPDIR%\%year% mkdir %BACKUPDIR%\%year% 
<br>
<br>
if not exist %BACKUPFILE% goto nofile 
<br>
goto ftpsession 
<br>
<br>
:nofile 
<br>
echo [FAILURE] can't find %BACKUPFILE% &gt;&gt; %LOGFILE% 
<br>
echo.&gt;&gt; %LOGFILE% 
<br>
goto end 
<br>
<br>
:ftpsession 
<br>
for /f "tokens=1-3 delims= " %%i in (ftp.cfg) do (set FTPSERVER=%%i&amp;set USERNAME=%%j&amp;set PASSWORD=%%k) 
<br>
echo open %FTPSERVER% &gt; ftpscript.txt 
<br>
echo user %USERNAME% %PASSWORD% &gt;&gt; ftpscript.txt 
<br>
echo mkdir %year%%month%%day% &gt;&gt; ftpscript.txt 
<br>
echo cd %year%%month%%day% &gt;&gt; ftpscript.txt 
<br>
echo bi &gt;&gt; ftpscript.txt 
<br>
echo put %BACKUPFILE% &gt;&gt; ftpscript.txt 
<br>
echo bye &gt;&gt; ftpscript.txt 
<br>
<br>
echo ---=== ftp session begins ===---&gt;&gt; %LOGFILE% 
<br>
echo ftp %BACKUPFILE% to %FTPSERVER% &gt;&gt; %LOGFILE% 
<br>
<br>
ftp -i -n &lt; ftpscript.txt &gt;&gt; %LOGFILE% 
<br>
<br>
echo ---=== ftp session ends ===---&gt;&gt; %LOGFILE% 
<br>
echo. |time | findstr "現在時間"&gt;&gt; %LOGFILE% 
<br>
echo.&gt;&gt; %LOGFILE% 
<br>
<br>
del ftpscript.txt 
<br>
<br>
set TARGET= 
<br>
set TARGETNAME= 
<br>
set BACKUPDIR= 
<br>
set BACKUPFILE= 
<br>
set LOGFILE= 
<br>
set FTPSERVER= 
<br>
set USERNAME= 
<br>
set PASSWORD= 
<br>
<br>
:end 
<br>
[/code] 
<br>
<br>
其中zip指令(取自[url=ftp://ftp.info-zip.org/pub/infozip/win32/]Info-ZIP[/url]發行之免費軟體）並非Windows內建的指令，請由本站下載，放到C:\Windows目錄下 
<br>
<br>
Windows內建的FTP指令說明可以透過執行ftp --usage指令得到： 
<br>
[code=plain] 
<br>
ftp --usage 
<br>
<br>
Transfers files to and from a computer running an FTP server service 
<br>
(sometimes called a daemon). Ftp can be used interactively. 
<br>
<br>
FTP [-v] [-d] [-i] [-n] [-g] [-s:filename] [-a] [-w:windowsize] [-A] [host] 
<br>
<br>
 -v Suppresses display of remote server responses. 
<br>
 -n Suppresses auto-login upon initial connection. 
<br>
 -i Turns off interactive prompting during multiple file 
<br>
 transfers. 
<br>
 -d Enables debugging. 
<br>
 -g Disables filename globbing (see GLOB command). 
<br>
 -s:filename Specifies a text file containing FTP commands; the 
<br>
 commands will automatically run after FTP starts. 
<br>
 -a Use any local interface when binding data connection. 
<br>
 -A login as anonymous. 
<br>
 -w:buffersize Overrides the default transfer buffer size of 4096. 
<br>
 host Specifies the host name or IP address of the remote 
<br>
 host to connect to. 
<br>
<br>
Notes: 
<br>
 - mget and mput commands take y/n/q for yes/no/quit. 
<br>
 - Use Control-C to abort commands.[/code] 
<br>
<br>
另外我把ftp的參數檔存放在ftp.cfg，內容如下 
<br>
[code]remotehost username password[/code] 
<br>
remotehost:請改成您的遠端主機IP(需有啟動FTP Server) 
<br>
username:請改成您的FTP帳號 
<br>
password:請改成您的FTP密碼 
<br>
<br>
執行完會在執行目錄下產生一個logfile，可供debug用。 
<br>
<br>
最後，遠端伺服器需先建立好對應的帳號及密碼，如有修改請記得回來改ftp.cfg 
<br>
<br>
參考資料： 
<br>
[url=http://www.microsoft.com/taiwan/technet/columns/profwin/28-monad.mspx]易學易用的 Windows PowerShell[/url] 
<br>]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/51.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/51.page</link>
				<pubDate><![CDATA[Wed, 7 Feb 2007 19:32:04]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ 首先謝謝你,我用了這個bat,超好用的^^ 
<br>
<br>
但有一個問題想問一下,如果我在壓縮的時候,可以有方法在這bat檔加上密碼才上傳到ftp嗎? 
<br>
<br>
因為我們要處理會計的文件,很機密的,謝謝 
<br>
<br>]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/510.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/510.page</link>
				<pubDate><![CDATA[Fri, 21 Nov 2008 12:55:52]]> GMT</pubDate>
				<author><![CDATA[ winglee007]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ 要加上密碼也是可以的，只要將原本的zip.exe換一個可以加密碼的壓縮軟體執行檔即可，例如7-Zip這個免費又可以加上密碼的壓縮軟體的7z.exe。 
<br>
1.到[url]http://www.7-zip.org/[/url]下載安裝用的exe檔 
<br>
2.執行下載的exe檔安裝 
<br>
3.安裝完成後，將C:\Program Files\7-Zip下的7z.exe複製到C:\Windows\System32目錄下。 
<br>
<br>
相關的參數可以在命令列下執行7z獲得： 
<br>
[code=plain]7-Zip 4.57 Copyright (c) 1999-2007 Igor Pavlov 2007-12-06 
<br>
<br>
Usage: 7z &lt;command&gt; [&lt;switches&gt;...] &lt;archive_name&gt; [&lt;file_names&gt;...] 
<br>
 [&lt;@listfiles...&gt;] 
<br>
<br>
&lt;Commands&gt; 
<br>
 a: Add files to archive 
<br>
 b: Benchmark 
<br>
 d: Delete files from archive 
<br>
 e: Extract files from archive (without using directory names) 
<br>
 l: List contents of archive 
<br>
 t: Test integrity of archive 
<br>
 u: Update files to archive 
<br>
 x: eXtract files with full paths 
<br>
&lt;Switches&gt; 
<br>
 -ai[r[-|0]]{@listfile|!wildcard}: Include archives 
<br>
 -ax[r[-|0]]{@listfile|!wildcard}: eXclude archives 
<br>
 -bd: Disable percentage indicator 
<br>
 -i[r[-|0]]{@listfile|!wildcard}: Include filenames 
<br>
 -m{Parameters}: set compression Method 
<br>
 -o{Directory}: set Output directory 
<br>
 -p{Password}: set Password 
<br>
 -r[-|0]: Recurse subdirectories 
<br>
 -scs{UTF-8 | WIN | DOS}: set charset for list files 
<br>
 -sfx[{name}]: Create SFX archive 
<br>
 -si[{name}]: read data from stdin 
<br>
 -slt: show technical information for l (List) command 
<br>
 -so: write data to stdout 
<br>
 -ssc[-]: set sensitive case mode 
<br>
 -ssw: compress shared files 
<br>
 -t{Type}: Set type of archive 
<br>
 -v{Size}[b|k|m|g]: Create volumes 
<br>
 -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]: Update options 
<br>
 -w[{path}]: assign Work directory. Empty path means a temporary directory 
<br>
 -x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames 
<br>
 -y: assume Yes on all queries[/code] 
<br>
<br>
以下是一個執行命令的範例，會將目前整個目錄壓縮起來存到c:\backup.zip檔案，並加上密碼secret。 
<br>
[code]7z a -psecret c:\backup.zip *[/code] 
<br>
<br>
所以原來程式簡易的修改方式如下： 
<br>
將第29行的程式碼取代為： 
<br>
[code="bat; first-line:29"]set ZIPPASSWORD=secret 
<br>
7z a -p%ZIPPASSWORD% %BACKUPFILE% %TARGET%\* [/code]]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/511.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/511.page</link>
				<pubDate><![CDATA[Fri, 21 Nov 2008 22:01:54]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ :thumbup:謝謝你～這個程式幫助很大。 
<br>
但是想請教一下，dos的指令，有沒有辦法抓取系統日前一日的日期呢？因為找了很久都找不到任何相關資訊，所以想請教一下，謝謝！]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/652.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/652.page</link>
				<pubDate><![CDATA[Thu, 1 Oct 2009 17:01:46]]> GMT</pubDate>
				<author><![CDATA[ starzine]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ 底下是我在網路上蒐尋[google]DOS batch 取得前一天的日期[/google]得到的資料，供您參考 
<br>
[code=bat] 
<br>
@echo off 
<br>
:: 作者： namejm 出自：cn-dos 
<br>
:: 求N天前的日期 
<br>
:: 日期可以帶星期，但是，必須以年月日的順序排列 
<br>
:: 年份必須是四位，否則會出錯 
<br>
@echo off 
<br>
:Main 
<br>
cls 
<br>
set day=%date% 
<br>
set days=0 
<br>
echo.&amp;echo. 
<br>
echo 當前日期是：%day% 
<br>
echo.&amp;set /p input= 請指定要追溯的天數： 
<br>
setlocal enabledelayedexpansion 
<br>
:: 提取日期 
<br>
for /f "tokens=1-3 delims=-/. " %%i in ("%day%") do ( 
<br>
 set /a sy=%%i, sm=100%%j %% 100, sd=100%%k %% 100 
<br>
) 
<br>
set /a sd-=input 
<br>
if %sd% leq 0 call :count 
<br>
cls&amp;echo.&amp;echo. 
<br>
echo 當前日期是：%day% 
<br>
echo. 
<br>
set sm=0%sm% 
<br>
set sd=0%sd% 
<br>
echo %input% 天前的日期是：%sy%-%sm:~-2%-%sd:~-2% 
<br>
pause&gt;nul 
<br>
goto Main 
<br>
<br>
:count 
<br>
set /a sm-=1 
<br>
if !sm! equ 0 set /a sm=12, sy-=1 
<br>
call :days 
<br>
set /a sd+=days 
<br>
if %sd% leq 0 goto count 
<br>
goto :eof 
<br>
<br>
:days 
<br>
:: 獲取指定月份的總天數 
<br>
set /a leap="^!(sy %% 4) &amp; ^!(^!(sy %% 100)) | ^!(sy %% 400)" 
<br>
set /a max=28+leap 
<br>
for /f "tokens=%sm%" %%i in ("31 %max% 31 30 31 30 31 31 30 31 30 31") do set days=%%i 
<br>
goto :eof 
<br>
[/code]]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/653.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/653.page</link>
				<pubDate><![CDATA[Thu, 1 Oct 2009 17:51:25]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ :thumbup:謝謝你，還蠻實用的，另外，想再請問一下，如何在dos底下，取出星期幾呢？應該是說，如何用date來取出星期？，目前已經研究出N天前的寫法，不過想再問一下是可否知道哪一天是星期幾？謝謝！]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/654.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/654.page</link>
				<pubDate><![CDATA[Fri, 2 Oct 2009 16:40:28]]> GMT</pubDate>
				<author><![CDATA[ starzine]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ 可以用下面的DOS指令取出目前的系統日期是星期幾 
<br>
echo %date:~-3% 
<br>
如果是要找出前N天是星期幾的話，可以先將系統日期暫存，然後改為前N天的日期，呼叫上面的指令即可取得星期幾，然後再將系統日期改回去。 
<br>
[code=bat]@echo off 
<br>
set prevday=2009/10/04 
<br>
set today=%date:~0,10% 
<br>
date %prevday% 
<br>
echo %date:~-3% 
<br>
date %today%[/code] 
<br>
參考資料： 
<br>
http://www.cnblogs.com/ustcyier/archive/2008/04/14/1152303.html]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/656.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/656.page</link>
				<pubDate><![CDATA[Mon, 5 Oct 2009 13:35:20]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ :thumbup:感謝～謝謝您幫我找到這個答案。最後想請問，一般工作日跟放假日，應該都是用比較高階的程式才能寫出來的吧？！Dos能夠寫出這樣的批次檔嗎？也就是說，能夠分辨營業日跟放假日嗎？一般的放假日（ex.六、日）這個部分可以克服（ex.抓取星期幾？），但是，若是遇到其他的假日（ex.中秋節）不是在六日的話，這樣好像就沒辦法了。謝謝！]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/657.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/657.page</link>
				<pubDate><![CDATA[Mon, 5 Oct 2009 16:22:25]]> GMT</pubDate>
				<author><![CDATA[ starzine]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ 我想山不轉路轉吧，可以用這樣的方式來達成， 
<br>
1.手動建立一個假日檔，例如檔名取叫holidays.txt，每行一個日期，樣子如下： 
<br>
2009/10/03 
<br>
2009/12/25 
<br>
<br>
2.從假日檔中每次讀取一行跟前N天的日期作比對，如果相同表示該前N天的日期即為假日，輸出 is a holiday的訊息 
<br>
<br>
底下是範例的程式碼： 
<br>
[code=bat] 
<br>
@echo off 
<br>
set prevday=2009/10/03 
<br>
set isHoliday=0 
<br>
for /f %%i in (holidays.txt) do call :checkHoliday %prevday% %%i 
<br>
if %isHoliday%==1 ( 
<br>
 echo %prevday% is a holiday 
<br>
) 
<br>
goto :end 
<br>
<br>
:checkHoliday 
<br>
if %1==%2 ( 
<br>
 set isHoliday=1 
<br>
) 
<br>
<br>
:end 
<br>
[/code]]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/658.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/658.page</link>
				<pubDate><![CDATA[Mon, 5 Oct 2009 19:06:24]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ 您好，不好意思，又有問題想請教。 
<br>
目前遇到ftp server的密碼為空白 
<br>
想請問一下cfg檔中的password若為空白時，該如何處理呢？謝謝！]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/947.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/947.page</link>
				<pubDate><![CDATA[Tue, 4 Jan 2011 17:40:40]]> GMT</pubDate>
				<author><![CDATA[ starzine]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ 據我所知，除非您是使用TFTP(Trivial File Transfer Protocol) Server，才不需要驗證，否則 
<br>
不用密碼就可以登入FTP Server :shock:好像不太可能（至少違反安全性，應該很難持續這種狀態），就算是匿名(Anonymous) FTP也是要輸入一下e-mail當作密碼的。 
<br>
<br>
如果您的系統真的不用輸入密碼，可以試試看將ftp.cfg編輯成類似下列的樣子，試試看有什麼錯誤訊息再回報吧： 
<br>
[code]remotehost username [/code] 
<br>
<br>
參考文件： 
<br>
http://www.sinica.edu.tw/ccc/sysinfo/desktop/ftp.pdf 
<br>
http://en.wikipedia.org/wiki/Trivial_File_Transfer_Protocol]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/949.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/949.page</link>
				<pubDate><![CDATA[Thu, 6 Jan 2011 10:24:37]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ 謝謝大大，您說的那個cfg我已經試過了，他是會在命令提示字元中出現password的字樣，也就是還是要請我們填入密碼，而若是在cfg中填入'' 或""，則是會出現錯誤訊息（也就是密碼錯誤），後來呢！就只能請對方設定帳號密碼，才能解決這個問題，不過呢！還是很謝謝大大的！ 
<br>
<br>
不過，還是有一件事想請問大大，不曉得大大有沒有玩過Windows server 2008呢？在做排定的工作時（排程），沒有辦法順利執行成功（也就是使用7-zip壓縮時，無法順利以排程完成工作），但權限的部份已經設定為最高權限了，不曉得是否還有什麼原因呢？謝謝囉！]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/950.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/950.page</link>
				<pubDate><![CDATA[Thu, 6 Jan 2011 10:49:06]]> GMT</pubDate>
				<author><![CDATA[ starzine]]></author>
			</item>
			<item>
				<title>[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ 您好,想請教老師: 
<br>
如果我只想把備份的檔案放到同一台電腦的其他槽區而已,那應該要改哪裡? 
<br>
 再請問老師,資料庫的資料可以如何自動備份 ? 
<br>
非常感謝!!]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/973.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/973.page</link>
				<pubDate><![CDATA[Wed, 26 Jan 2011 14:38:00]]> GMT</pubDate>
				<author><![CDATA[ n5998744]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ n5998744您好: 
<br>
如果只要把備份的檔案放到同一台電腦的其他槽區而已=&gt;就是不作FTP的動作囉？ 
<br>
那就把ftpsession那段跳過去即可，可以修改remote_backup_web.bat的第34行 
<br>
[code=bat;first-line:34] 
<br>
 goto ftpsession 
<br>
[/code] 
<br>
為 
<br>
[code=bat;first-line:34] 
<br>
 goto end 
<br>
[/code] 
<br>
如果要更改備份檔所在的目錄，可以修改第21行 
<br>
[code=bat;first-line:21] 
<br>
 set BACKUPDIR=D:\backup 
<br>
[/code] 
<br>
<br>
不知道您是使用何種資料庫軟體，如果是使用MS SQL Server，要備份資料庫到本機硬碟的話就很簡單，可以在資料庫軟體上設定排程，將資料庫備份到某一個目錄下即可。]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/974.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/974.page</link>
				<pubDate><![CDATA[Fri, 28 Jan 2011 17:23:53]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ [color=darkblue]您好：因為又遇到了點難題，想來請教一下是否有任何可以解決的方法。 
<br>
<br>
目前以cfg的檔案抓取資料都沒有問題，但是目前對方把ftp移至安全環境底下 
<br>
開啟了相關的port如下： 
<br>
HTTP安全連線：https-443 
<br>
FTP安全連線：ftp-21(也有支援安全通道)、ftps-990(也可用此安全通道連線) 
<br>
FTP被動模式：port-50000~50009 
<br>
SSL認證：990, 989 
<br>
SFTP：22 
<br>
FTP傳輸資料：20 
<br>
<br>
而因為這樣，目前所使用的cfg無法連接上，用一般的FTP軟體也沒有辦法（雖然有提供21port，但似乎是因為沒有安全性，所以被拒絕了） 
<br>
請問cfg的部分應該怎麼處理呢？謝謝！[/color]]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/1162.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/1162.page</link>
				<pubDate><![CDATA[Tue, 18 Oct 2011 15:53:05]]> GMT</pubDate>
				<author><![CDATA[ starzine]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ 試著改用[url=http://the.earth.li/~sgtatham/putty/latest/x86/psftp.exe]psftp[/url]這個程式來執行SFTP的工作看看 
<br>
將原先使用ftp的指令改為psftp指令，下載後將psftp.exe放在remote_backup_web.bat相同目錄即可。 
<br>
remote_backup_web.bat: 
<br>
[code=batch] 
<br>
@echo off 
<br>
rem --------------------------------------------------------------------------- 
<br>
rem Backup web application to remote host 
<br>
rem 
<br>
rem $Id: remote_backup_web.bat 2011-10-20 07:10:58 andowson $ 
<br>
rem --------------------------------------------------------------------------- 
<br>
<br>
rem Find out Windows version 
<br>
for /f "tokens=1-2 delims=[" %%i in ('ver') do echo %%j &gt; ver1.txt 
<br>
for /f "tokens=1-2 delims= " %%i in (ver1.txt) do echo %%j &gt; ver2.txt 
<br>
for /f "tokens=1 delims=]" %%i in (ver2.txt) do set vers=%%i 
<br>
del ver1.txt 
<br>
del ver2.txt 
<br>
if %vers% GEQ 6 goto ver6 
<br>
<br>
rem Find out web server's IP address 
<br>
ipconfig | findstr "Address" &gt; ip1.txt 
<br>
for /f "tokens=1-2 delims=:" %%i in (ip1.txt) do echo %%j &gt; ip2.txt 
<br>
for /f "tokens=1-2 delims= " %%i in (ip2.txt) do (set ip=%%i) 
<br>
del ip1.txt 
<br>
del ip2.txt 
<br>
goto common 
<br>
<br>
:ver6 
<br>
rem Find out web server's IP address 
<br>
ipconfig | findstr "IPv4 位址" &gt; ip1.txt 
<br>
for /f "tokens=1-2 delims=:" %%i in (ip1.txt) do echo %%j &gt; ip2.txt 
<br>
for /f "tokens=1-2 delims= " %%i in (ip2.txt) do (set ip=%%i) 
<br>
del ip1.txt 
<br>
del ip2.txt 
<br>
<br>
:common 
<br>
rem Get today's year, month, day 
<br>
for /f "tokens=1-3 delims=/ " %%a in ('date /t') do (set year=%%a&amp; set month=%%b&amp; set day=%%c) 
<br>
<br>
rem Modify the following line for your environment 
<br>
set TARGETNAME=demoweb 
<br>
set TARGET=C:\Inetpub\wwwroot\%TARGETNAME% 
<br>
set BACKUPDIR=D:\backup 
<br>
set BACKUPFILE=%BACKUPDIR%\%year%\%TARGETNAME%_%ip%_%year%%month%%day%.zip 
<br>
set LOGFILE=%TARGETNAME%_backup.log 
<br>
set ZIPPASSWORD=secret 
<br>
<br>
echo. | date | findstr "現在日期" &gt;&gt; %LOGFILE% 
<br>
echo. | time | findstr "現在時間" &gt;&gt; %LOGFILE% 
<br>
<br>
rem Compress the target directory with encryption password before ftp 
<br>
"C:\Program Files\7-Zip\7z.exe" a -p%ZIPPASSWORD% %BACKUPFILE% %TARGET%\* &gt;&gt; %LOGFILE% 
<br>
<br>
if not exist %BACKUPDIR%\%year% mkdir %BACKUPDIR%\%year% 
<br>
<br>
if not exist %BACKUPFILE% goto nofile 
<br>
goto ftpsession 
<br>
<br>
:nofile 
<br>
echo [FAILURE] File not found: %BACKUPFILE% &gt;&gt; %LOGFILE% 
<br>
echo.&gt;&gt; %LOGFILE% 
<br>
goto end 
<br>
<br>
:ftpsession 
<br>
for /f "tokens=1-3 delims= " %%i in (ftp.cfg) do (set FTPSERVER=%%i&amp;set USERNAME=%%j&amp;set PASSWORD=%%k) 
<br>
echo mkdir %year%%month%%day% &gt; ftpscript.txt 
<br>
echo cd %year%%month%%day% &gt;&gt; ftpscript.txt 
<br>
echo put %BACKUPFILE% &gt;&gt; ftpscript.txt 
<br>
echo bye &gt;&gt; ftpscript.txt 
<br>
<br>
echo ---=== ftp session begin ===---&gt;&gt; %LOGFILE% 
<br>
echo ftp %BACKUPFILE% to %FTPSERVER% &gt;&gt; %LOGFILE% 
<br>
<br>
psftp %FTPSERVER% -l %USERNAME% -pw %PASSWORD% -be -b ftpscript.txt &gt;&gt; %LOGFILE% 
<br>
<br>
echo ---=== ftp session end ===---&gt;&gt; %LOGFILE% 
<br>
echo. |time | findstr "現在時間"&gt;&gt; %LOGFILE% 
<br>
echo.&gt;&gt; %LOGFILE% 
<br>
<br>
del ftpscript.txt 
<br>
<br>
set TARGET= 
<br>
set TARGETNAME= 
<br>
set BACKUPDIR= 
<br>
set BACKUPFILE= 
<br>
set LOGFILE= 
<br>
set ZIPPASSWORD= 
<br>
set FTPSERVER= 
<br>
set USERNAME= 
<br>
set PASSWORD= 
<br>
<br>
:end 
<br>
[/code] 
<br>
<br>
ftp.cfg可以使用原來的格式，也是放在跟remote_backup_web.bat相同目錄下: 
<br>
[code]remote_sftp_server username password[/code] 
<br>
<br>
最後先開啟一個CMD命令視窗，然後利用cd切換工作目錄到存放remote_backup_web.bat的目錄下 
<br>
手動執行一次remote_backup_web.bat，測試是否可以正常運作。因為第一次連線至SFTP Server需要驗證主機端的憑證，會詢問是否要儲存遠端主機的key，選擇yes。 
<br>
<br>
有關psftp的使用說明請參考下列網址: 
<br>
http://libai.math.ncu.edu.tw/bcc16/6/putty/psftp.html 
<br>
<br>
註:本batch script中含有部份中文字串，存檔時請注意選擇編碼為ANSI/Windows]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/1163.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/1163.page</link>
				<pubDate><![CDATA[Wed, 19 Oct 2011 12:37:24]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ [color=darkblue]大大您好： 
<br>
<br>
 不好意思又有問題想請教，因為對DOS的指令實在是很不熟悉。 
<br>
 因為需要在FTP中的各個資料夾中抓取所需的資料， 
<br>
 所以需要A資料夾抓完後，再到上一層資料夾，再至B資料夾。 
<br>
 原本想說可以把要抓的資料夾寫成一個txt檔，就像大大上面寫的holiday.txt一樣。 
<br>
 不過在FTP中，好像不太能用for這個語法。 
<br>
<br>
 我的寫法如下： 
<br>
 echo lcd %BACKUPDIR% &gt;&gt; ftpscript.txt 
<br>
 for /f "tokens=1-50 delims= " %%i in (pbank.txt) do( 
<br>
 echo cd %FTPDIR%&gt;&gt;ftpscript.txt 
<br>
 echo mget *%year%%month%%day%.*&gt;&gt; ftpscript.txt 
<br>
 echo cd \&gt;&gt; ftpscript.txt 
<br>
 ) 
<br>
 目前FTP好像到這一段就不跑了。 
<br>
<br>
 所以可否請看看還有沒有什麼辦法？ 
<br>
 感謝！[/color]]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/1173.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/1173.page</link>
				<pubDate><![CDATA[Thu, 10 Nov 2011 15:43:13]]> GMT</pubDate>
				<author><![CDATA[ starzine]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ starzine您好， 
<br>
看起來你的for迴圈那段有點問題，如果你是一行一筆資料的話，請參考先前我的holiday.bat裡面的寫法。 
<br>
[code=batch] 
<br>
echo lcd %BACKUPDIR% &gt;&gt; ftpscript.txt 
<br>
echo prompt &gt;&gt; ftpscript.txt 
<br>
for /f %%i in (pbank.txt) do ( 
<br>
 echo cd %%i &gt;&gt;ftpscript.txt 
<br>
 echo mget *%year%%month%%day%.* &gt;&gt; ftpscript.txt 
<br>
 echo cd .. &gt;&gt; ftpscript.txt 
<br>
) 
<br>
[/code] 
<br>
又你可以先把你的測試程式寫成一個小bat檔，測試看看能不能動，再貼回原來的主程式去。 
<br>
<br>]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/1175.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/1175.page</link>
				<pubDate><![CDATA[Thu, 10 Nov 2011 18:26:47]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ 大大您好： 
<br>
<br>
 感謝您的回答，不過因為您寫的那個holiday.bat...我其實看不是很懂，可否請您稍微解釋一下呢？麻煩您了！ 
<br>
<br>
[color=blue][/color]]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/1176.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/1176.page</link>
				<pubDate><![CDATA[Fri, 11 Nov 2011 15:12:37]]> GMT</pubDate>
				<author><![CDATA[ starzine]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ 我的意思是指如果您想要拜訪(visit)holidays.txt檔案中每一行的資料時，只要寫成下面的 for迴圈即可: 
<br>
[code=batch]@echo off 
<br>
for /f %%i in (holidays.txt) do ( 
<br>
 echo %%i is a holiday 
<br>
)[/code] 
<br>
[color=red]%%i[/color] 就是迴圈每前進一圈時，由holidays.txt所讀出的下一筆資料 
<br>
假設holidays.txt內容如下 
<br>
[code=text]2011/1/1 
<br>
2011/2/2 
<br>
2011/2/28 
<br>
2011/4/4 
<br>
2011/4/5 
<br>
2011/6/6 
<br>
2011/9/12 
<br>
2011/10/10[/code] 
<br>
將會依序印出: 
<br>
[code=text]2011/1/1 is a holiday 
<br>
2011/2/2 is a holiday 
<br>
2011/2/28 is a holiday 
<br>
2011/4/4 is a holiday 
<br>
2011/4/5 is a holiday 
<br>
2011/6/6 is a holiday 
<br>
2011/9/12 is a holiday 
<br>
2011/10/10 is a holiday[/code]]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/1177.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/1177.page</link>
				<pubDate><![CDATA[Fri, 11 Nov 2011 17:41:41]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ [quote=andowson]我的意思是指如果您想要拜訪(visit)holidays.txt檔案中每一行的資料時，只要寫成下面的 for迴圈即可: 
<br>
[code=batch]@echo off 
<br>
for /f %%i in (holidays.txt) do ( 
<br>
 echo %%i is a holiday 
<br>
)[/code] 
<br>
[color=red]%%i[/color] 就是迴圈每前進一圈時，由holidays.txt所讀出的下一筆資料 
<br>
假設holidays.txt內容如下 
<br>
[code=text]2011/1/1 
<br>
2011/2/2 
<br>
2011/2/28 
<br>
2011/4/4 
<br>
2011/4/5 
<br>
2011/6/6 
<br>
2011/9/12 
<br>
2011/10/10[/code] 
<br>
將會依序印出: 
<br>
[code=text]2011/1/1 is a holiday 
<br>
2011/2/2 is a holiday 
<br>
2011/2/28 is a holiday 
<br>
2011/4/4 is a holiday 
<br>
2011/4/5 is a holiday 
<br>
2011/6/6 is a holiday 
<br>
2011/9/12 is a holiday 
<br>
2011/10/10 is a holiday[/code][/quote] 
<br>
<br>
不好意思大大： 
<br>
<br>
我還是不太明白，那這個@echo off可以寫在FTP裡面嗎？ 
<br>
因為我寫了一個小批次後，還是不太能夠work... 
<br>
例如： 
<br>
@echo off 
<br>
for /f %%i in (pbank.txt) do( 
<br>
echo %%i 
<br>
) 
<br>
寫了do之後，按了以後，do不能用。 
<br>
另外%%i可否變成%%m? 
<br>
真的很抱歉，麻煩您再協助一下！]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/1179.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/1179.page</link>
				<pubDate><![CDATA[Wed, 23 Nov 2011 16:25:57]]> GMT</pubDate>
				<author><![CDATA[ starzine]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ starzine您好: 
<br>
還是老話一句，請仔細觀察我的範例程式，細節就是魔鬼啦: 
<br>
將您的小批次檔存檔為test.bat，利用cmd開啟一個DOS 命令視窗後，執行test，顯示下列的錯誤訊息 
<br>
[quote]這個時候不應有 do(。[/quote] 
<br>
不知道您有沒有發現，我的範例程式do和(中間有空一格? 
<br>
將do(改為do (後，test.bat就可以正常執行了(前提是假設pbank.txt存在啦) 
<br>
<br>
另外，%%i可否變成%%m? 
<br>
這個當然是可以的，不過要改完整就是了，不要只改到一個地方: 
<br>
[code=batch]@echo off 
<br>
for /f %%m in (pbank.txt) do ( 
<br>
echo %%m 
<br>
)[/code] 
<br>
<br>
最後我不清楚你問的@echo off可以寫在FTP裡面嗎？ 這裡的FTP是指ftpscript.txt嗎?]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/1180.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/1180.page</link>
				<pubDate><![CDATA[Thu, 24 Nov 2011 00:52:27]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ [color=darkblue]大大您好： 
<br>
不好意思又打擾了， 
<br>
有兩個問題 
<br>
我把.txt檔寫在FTP中。大概如下[/color] 
<br>
[code=batch] 
<br>
echo open %FTPSERVER% &gt; ftpscript.txt 
<br>
echo user %USERNAME% %PASSWORD% &gt;&gt; ftpscript.txt 
<br>
echo lcd %BACKUPDIR% &gt;&gt; ftpscript.txt 
<br>
for /f %%m in (pbank.txt) do ( 
<br>
echo cd %%m&gt;&gt;ftpscript.txt 
<br>
rem echo mget *%year%%month%%day%.*&gt;&gt; ftpscript.txt 
<br>
echo mget *.*&gt;&gt; ftpscript.txt 
<br>
echo cd \&gt;&gt; ftpscript.txt 
<br>
 ) 
<br>
echo cd %FTPDIR2%&gt;&gt;ftpscript.txt 
<br>
echo mget *%year%%month%%day%.*&gt;&gt; ftpscript.txt 
<br>
rem echo get *.*&gt;&gt; ftpscript.txt 
<br>
echo dir *%year%%month%%day%.*&gt;&gt; ftpscript.txt 
<br>
rem echo mget *.*&gt;&gt; ftpscript.txt 
<br>
echo bye &gt;&gt; ftpscript.txt 
<br>
echo ---=== ftp session begins ===---&gt;&gt; %LOGFILE% 
<br>
echo ftp %FTPSERVER% to %BACKUPDIR% &gt;&gt; %LOGFILE% 
<br>
echo mget *%year%%month%%day%.*&gt;&gt;%LOGFILE% 
<br>
[/code] 
<br>
[color=darkblue]我的想法是，迴圈再進入該資料夾後，抓取所有的資料完畢，再回上一層，然後再進入下一個資料夾。而log檔案的確是有進入每一個資料夾，但是卻沒有辦法抓取任何的檔案。想請問是否有哪裡有錯誤？ 
<br>
另外一個問題是，可否抓取系統日的資料呢？（因為無法從資料檔名來做區別，所以可否以系統日的資料來抓取？） 
<br>
不好意思，打擾了。[/color]]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/1187.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/1187.page</link>
				<pubDate><![CDATA[Thu, 5 Jan 2012 17:12:06]]> GMT</pubDate>
				<author><![CDATA[ starzine]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ starzine您好: 
<br>
可否先將bat檔中的這一行註解掉: 
<br>
[code=bat]del ftpscript.txt[/code] 
<br>
方法就是前面加上rem，如下: 
<br>
[code=bat]rem del ftpscript.txt[/code] 
<br>
然後你再執行一次，接著你把ftpscript.txt和log檔都傳上來，比較方便除錯，謝謝~ 
<br>
<br>]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/1188.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/1188.page</link>
				<pubDate><![CDATA[Thu, 5 Jan 2012 18:26:50]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ [quote=andowson]starzine您好: 
<br>
可否先將bat檔中的這一行註解掉: 
<br>
[code=bat]del ftpscript.txt[/code] 
<br>
方法就是前面加上rem，如下: 
<br>
[code=bat]rem del ftpscript.txt[/code] 
<br>
然後你再執行一次，接著你把ftpscript.txt和log檔都傳上來，比較方便除錯，謝謝~ 
<br>
[/quote] 
<br>
大大您好： 
<br>
我的整個程式是這樣的寫法 
<br>
[code=bat] 
<br>
@echo off 
<br>
set BACKUPDIR=s:\upload 
<br>
set BACKUPDIR2=s:\uploadbackup 
<br>
set BACKUPFILE=%BACKUPDIR2%\%year%%month%%day% 
<br>
set FTPDIR2=FundX 
<br>
set LOGFILE=%year%%month%%day%_backup.log 
<br>
<br>
echo wscript.echo dateadd("d",-2,date) &gt;%tmp%\tmp.vbs 
<br>
for /f "tokens=1-3 delims=/ " %%a in ('cscript /nologo %tmp%\tmp.vbs') do (set year=%%a&amp; set month=%%b&amp; set day=%%c) 
<br>
 if %month% LEQ 9 set month=0%month% 
<br>
 if %day% LEQ 9 set day=0%day% 
<br>
<br>
echo. | date | findstr "現在日期" &gt;&gt; %LOGFILE% 
<br>
echo. | time | findstr "現在時間" &gt;&gt; %LOGFILE% 
<br>
<br>
:ftpsession 
<br>
for /f "tokens=1-3 delims= " %%i in (ftp.cfg) do (set FTPSERVER=%%i&amp;set USERNAME=%%j&amp;set PASSWORD=%%k) 
<br>
<br>
echo open %FTPSERVER% &gt; ftpscript.txt 
<br>
echo user %USERNAME% %PASSWORD% &gt;&gt; ftpscript.txt 
<br>
echo lcd %BACKUPDIR% &gt;&gt; ftpscript.txt 
<br>
for /f %%m in (pbank.txt) do ( 
<br>
echo cd %%m&gt;&gt;ftpscript.txt 
<br>
echo mget *%year%%month%%day%.*&gt;&gt; ftpscript.txt 
<br>
rem echo mget *.*&gt;&gt; ftpscript.txt 
<br>
echo cd \&gt;&gt; ftpscript.txt 
<br>
 ) 
<br>
echo cd %FTPDIR2%&gt;&gt;ftpscript.txt 
<br>
echo mget *%year%%month%%day%.*&gt;&gt; ftpscript.txt 
<br>
rem echo get *.*&gt;&gt; ftpscript.txt 
<br>
echo dir *%year%%month%%day%.*&gt;&gt; ftpscript.txt 
<br>
rem echo mget *.*&gt;&gt; ftpscript.txt 
<br>
echo bye &gt;&gt; ftpscript.txt 
<br>
echo ---=== ftp session begins ===---&gt;&gt; %LOGFILE% 
<br>
echo ftp %FTPSERVER% to %BACKUPDIR% &gt;&gt; %LOGFILE% 
<br>
echo mget *%year%%month%%day%.*&gt;&gt;%LOGFILE% 
<br>
<br>
psftp %FTPSERVER% -l %USERNAME% -pw %PASSWORD% -be -b ftpscript.txt &gt;&gt; %LOGFILE% 
<br>
<br>
xcopy s:\upload\*%year%%month%%day%.* S:\uploadbackup /E/C/Q/R/Y 
<br>
xcopy s:\upload\*.* S:\uploadbackup /E/C/Q/R/Y 
<br>
if not exist %BACKUPDIR2%\%year%%month%%day% mkdir %BACKUPDIR2%\%year%%month%%day% 
<br>
move /Y s:\uploadbackup\*%year%%month%%day%.* %BACKUPDIR2%\%year%%month%%day% 
<br>
move /Y s:\uploadbackup\*.* %BACKUPDIR2%\%year%%month%%day% 
<br>
<br>
echo ---=== ftp session ends ===---&gt;&gt; %LOGFILE% 
<br>
echo. |time | findstr "現在時間"&gt;&gt; %LOGFILE% 
<br>
echo %BACKUPDIR2%\%year%%month%%day%&gt;&gt; %LOGFILE% 
<br>
echo %BACKUPFILE1%&gt;&gt; %LOGFILE% 
<br>
echo.&gt;&gt; %LOGFILE% 
<br>
rem del ftpscript.txt 
<br>
rem del %LOGFILE%_backup.log 
<br>
move /Y I:\wSTN_IO\_backup.log %BACKUPDIR2%\%year%%month%%day% 
<br>
move /Y I:\wSTN_IO\ftpscript.txt %BACKUPDIR2%\%year%%month%%day% 
<br>
<br>
set TARGET= 
<br>
set TARGETNAME= 
<br>
set BACKUPDIR= 
<br>
set BACKUPFILE= 
<br>
set LOGFILE= 
<br>
set FTPSERVER= 
<br>
set USERNAME= 
<br>
set PASSWORD= 
<br>
:end 
<br>
[/code] 
<br>
那關於ftpscript.txt是這樣 
<br>
[code=bat] 
<br>
open 61.66.19X.XXX 
<br>
user S00XX S0XXX 
<br>
lcd s:\upload 
<br>
cd A0001 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0002 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0003 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0004 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0005 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0006 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0007 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0008 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0009 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0010 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0011 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0012 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0013 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0014 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0015 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0016 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0017 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0018 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0019 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0020 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0021 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0022 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0023 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0024 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0025 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0026 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0027 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0028 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0029 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0030 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0031 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0032 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0033 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0034 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0035 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0036 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0037 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0038 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0039 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0040 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0041 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0042 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0043 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0044 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0045 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0046 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0047 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0048 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0049 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd A0099 
<br>
mget *20120104.* 
<br>
cd \ 
<br>
cd FundX 
<br>
mget *20120104.* 
<br>
dir *20120104.* 
<br>
bye 
<br>
[/code] 
<br>
有兩個問題 
<br>
1. 在執行這個.bat檔時，似乎沒辦法執行完畢。 
<br>
2. 也沒有相關的log記錄。 
<br>
可是從ftpscript.txt來看，應該是有跑了每一個資料夾。 
<br>
但是卻沒有將任何資料下載下來。 
<br>
這是很奇怪的一件事。 
<br>
再麻煩大大了！]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/1189.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/1189.page</link>
				<pubDate><![CDATA[Fri, 6 Jan 2012 15:04:47]]> GMT</pubDate>
				<author><![CDATA[ starzine]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ 初步修正如下: 
<br>
[code=bat]@echo off 
<br>
echo wscript.echo dateadd("d",-2,date) &gt;%tmp%\tmp.vbs 
<br>
for /f "tokens=1-3 delims=/ " %%a in ('cscript /nologo %tmp%\tmp.vbs') do (set year=%%a&amp; set month=%%b&amp; set day=%%c) 
<br>
 if %month% LEQ 9 set month=0%month% 
<br>
 if %day% LEQ 9 set day=0%day% 
<br>
rem 去掉字串尾端空白 
<br>
set day=%day:~,2% 
<br>
<br>
set BACKUPDIR=s:\upload 
<br>
set BACKUPDIR2=s:\uploadbackup 
<br>
set BACKUPFILE=%BACKUPDIR2%\%year%%month%%day% 
<br>
set FTPDIR2=FundX 
<br>
set LOGFILE=%year%%month%%day%_backup.log 
<br>
echo %LOGFILE% 
<br>
echo. | date | findstr "現在日期" &gt;&gt; %LOGFILE% 
<br>
echo. | time | findstr "現在時間" &gt;&gt; %LOGFILE% 
<br>
<br>
:ftpsession 
<br>
for /f "tokens=1-3 delims= " %%i in (ftp.cfg) do (set FTPSERVER=%%i&amp;set USERNAME=%%j&amp;set PASSWORD=%%k) 
<br>
<br>
rem echo open %FTPSERVER% &gt; ftpscript.txt 
<br>
rem echo user %USERNAME% %PASSWORD% &gt;&gt; ftpscript.txt 
<br>
echo lcd %BACKUPDIR% &gt; ftpscript.txt 
<br>
for /f %%m in (pbank.txt) do ( 
<br>
 echo cd %%m&gt;&gt;ftpscript.txt 
<br>
 echo mget *%year%%month%%day%.*&gt;&gt; ftpscript.txt 
<br>
 rem echo mget *.*&gt;&gt; ftpscript.txt 
<br>
 echo cd ..&gt;&gt; ftpscript.txt 
<br>
) 
<br>
echo cd %FTPDIR2%&gt;&gt;ftpscript.txt 
<br>
echo mget *%year%%month%%day%.*&gt;&gt; ftpscript.txt 
<br>
rem echo get *.*&gt;&gt; ftpscript.txt 
<br>
echo dir *%year%%month%%day%.*&gt;&gt; ftpscript.txt 
<br>
rem echo mget *.*&gt;&gt; ftpscript.txt 
<br>
echo bye &gt;&gt; ftpscript.txt 
<br>
echo ---=== ftp session begins ===---&gt;&gt; %LOGFILE% 
<br>
echo ftp %FTPSERVER% to %BACKUPDIR% &gt;&gt; %LOGFILE% 
<br>
echo mget *%year%%month%%day%.*&gt;&gt;%LOGFILE% 
<br>
<br>
psftp %FTPSERVER% -l %USERNAME% -pw %PASSWORD% -be -b ftpscript.txt &gt;&gt; %LOGFILE% 
<br>
<br>
xcopy %BACKUPDIR%\*%year%%month%%day%.* %BACKUPDIR2% /E/C/Q/R/Y 
<br>
xcopy %BACKUPDIR%\*.* %BACKUPDIR2% /E/C/Q/R/Y 
<br>
if not exist %BACKUPDIR2%\%year%%month%%day% mkdir %BACKUPDIR2%\%year%%month%%day% 
<br>
move /Y %BACKUPDIR2%\*%year%%month%%day%.* %BACKUPDIR2%\%year%%month%%day% 
<br>
move /Y %BACKUPDIR2%\*.* %BACKUPDIR2%\%year%%month%%day% 
<br>
<br>
echo ---=== ftp session ends ===---&gt;&gt; %LOGFILE% 
<br>
echo. |time | findstr "現在時間"&gt;&gt; %LOGFILE% 
<br>
echo %BACKUPDIR2%\%year%%month%%day%&gt;&gt; %LOGFILE% 
<br>
echo %BACKUPFILE1%&gt;&gt; %LOGFILE% 
<br>
echo.&gt;&gt; %LOGFILE% 
<br>
rem del ftpscript.txt 
<br>
rem del %LOGFILE% 
<br>
move /Y I:\wSTN_IO\%LOGFILE% %BACKUPDIR2%\%year%%month%%day% 
<br>
move /Y I:\wSTN_IO\ftpscript.txt %BACKUPDIR2%\%year%%month%%day% 
<br>
<br>
set TARGET= 
<br>
set TARGETNAME= 
<br>
set BACKUPDIR= 
<br>
set BACKUPFILE= 
<br>
set LOGFILE= 
<br>
set FTPSERVER= 
<br>
set USERNAME= 
<br>
set PASSWORD= 
<br>
:end[/code] 
<br>
<br>
說明如下: 
<br>
將原8~11行搬移至第2行以取得year month day變數的定義 
<br>
[color=red]增加第7行, 修正day變數尾端有空白字串的bug[/color] 
<br>
刪除(這裡我先用rem註解掉)原程式中的19-20行 
<br>
[code]rem echo open %FTPSERVER% &gt; ftpscript.txt 
<br>
rem echo user %USERNAME% %PASSWORD% &gt;&gt; ftpscript.txt[/code] 
<br>
同時修改原第21行如下: 
<br>
[code]echo lcd %BACKUPDIR% &gt; ftpscript.txt[/code] 
<br>
另外我不知道你用cd \的原因為何，是否可以試著把cd \ 改為cd .. 
<br>
將原第26行改為 
<br>
[code]echo cd ..&gt;&gt; ftpscript.txt[/code] 
<br>
<br>
參考資料: 
<br>
[url=http://tw.myblog.yahoo.com/blue-comic/article?mid=451&amp;prev=541&amp;l=f&amp;fid=25]幾個在寫 MS-DOS batch script 時好用的動作[/url]]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/1190.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/1190.page</link>
				<pubDate><![CDATA[Fri, 6 Jan 2012 16:27:02]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ 說明如下: 
<br>
將原8~11行搬移至第2行以取得year month day變數的定義 
<br>
[color=red]增加第7行, 修正day變數尾端有空白字串的bug[/color] 
<br>
刪除(這裡我先用rem註解掉)原程式中的19-20行 
<br>
[code]rem echo open %FTPSERVER% &gt; ftpscript.txt 
<br>
rem echo user %USERNAME% %PASSWORD% &gt;&gt; ftpscript.txt[/code] 
<br>
同時修改原第21行如下: 
<br>
[code]echo lcd %BACKUPDIR% &gt; ftpscript.txt[/code] 
<br>
另外我不知道你用cd \的原因為何，是否可以試著把cd \ 改為cd .. 
<br>
將原第26行改為 
<br>
[code]echo cd ..&gt;&gt; ftpscript.txt[/code] 
<br>
<br>
參考資料: 
<br>
[url=http://tw.myblog.yahoo.com/blue-comic/article?mid=451&amp;prev=541&amp;l=f&amp;fid=25]幾個在寫 MS-DOS batch script 時好用的動作[/url][/quote] 
<br>
<br>
大大您好： 
<br>
謝謝您的建議，我會把程式再稍做修改。 
<br>
但有一個問題想請教，要如何抓取系統日的檔案呢？ 
<br>
也就是說，如果今天是1/9日，我想抓取修改日期是1/6日的資料，但檔案名稱不見得是0106的資料。 
<br>
請問有辦法可以做的到嗎？ 
<br>
還有，若是有這樣的問題時，若在Google上欲搜尋，應該下什麼樣的關鍵字呢？ 
<br>
麻煩您囉！ 
<br>]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/1192.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/1192.page</link>
				<pubDate><![CDATA[Mon, 9 Jan 2012 16:38:01]]> GMT</pubDate>
				<author><![CDATA[ starzine]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ 您可以參考下面的範例程式去修改 
<br>
[code=bat]@echo off 
<br>
rem 取得系統日期 
<br>
for /f "tokens=1 delims= " %%a in ('date /T') do set today=%%a 
<br>
<br>
rem 先找出現行目錄下所有檔案並依日期排序後再過濾出日期為系統日期之檔案存到dir.txt 
<br>
dir /A:-D /O:D | find /i "%today%" &gt; dir.txt 
<br>
<br>
if exist filelist.txt del filelist.txt 
<br>
rem 利用空白字元切割，由dir.txt每列的第五欄中取得檔案名稱 
<br>
for /f "tokens=5 delims= " %%a in (dir.txt) do ( 
<br>
 echo %%a &gt;&gt; filelist.txt 
<br>
 rem 下面可以開始抓檔案了 
<br>
 rem get %%a 
<br>
)[/code] 
<br>
<br>
我是利用[google]DOS file date[/google]這樣子的關鍵字去搜尋的 
<br>
參考資料: 
<br>
http://www.computing.net/answers/dos/dos-batch-to-check-file-date/12627.html]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/1193.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/1193.page</link>
				<pubDate><![CDATA[Mon, 9 Jan 2012 18:18:07]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ [quote=andowson] 
<br>
另外我不知道你用cd \的原因為何，是否可以試著把cd \ 改為cd .. 
<br>
將原第26行改為 
<br>
[code]echo cd ..&gt;&gt; ftpscript.txt[/code][/quote] 
<br>
<br>
[color=darkblue]大大您好： 
<br>
謝謝您的協助，後來經過測試後，發現第26行改成這樣就行了[/color] 
<br>
[code]echo cd &gt;&gt; ftpscript.txt[/code] 
<br>
[color=red]也就是說psftp好像只懂得cd 
<br>
而不懂得cd..或cd\[/color] 
<br>
<br>
[color=darkblue]這也是經過實驗之後才得到的結果。 
<br>
<br>
另外，關於系統日期的部分， 
<br>
我是想要在透過psftp連線到遠端的主機上，得到遠端主機上每個資料夾的修改日期。 
<br>
再以遠端主機上的資料夾以修改日期排序。 
<br>
再進入各個資料夾中抓取該修改日期之資料 
<br>
想抓取系統日期的前一天的資料，但其檔名不見得係以修改日期來命名。 
<br>
<br>
不過發現psftp似乎沒有支援相關指令可以用日期來排序。 
<br>
<br>
目前也只找到ls 和dir可以使用。 
<br>
但是ls 及dir 似乎沒有更進階的指令來作為排序的動作。（ex.dir -D之類的） 
<br>
好像都無法按照日期排序。 
<br>
目前好像只能用資料夾名稱排序。 
<br>
<br>
所以似乎沒辦法使用大大下方所寫的程式。 
<br>
大大所提供的程式，是否只能適用於本機端呢？ 
<br>
<br>
還是說，還有什麼方法呢？ 
<br>
謝謝大大囉！[/color]]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/1194.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/1194.page</link>
				<pubDate><![CDATA[Wed, 11 Jan 2012 16:49:34]]> GMT</pubDate>
				<author><![CDATA[ starzine]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ starzine您好: 
<br>
我給的範例確實是只能在本機端執行，取得本機端的檔案名稱，而您所需要的是取得遠端檔案伺服器目錄下的檔案清單。 
<br>
可以在sftp下執行目錄排序的指令如下(日期最近的會排在上面) 
<br>
ls -lt 
<br>
但接下來可能你會問要如何從psftp將這個指令的結果(目錄內的檔案清單)傳回，好讓我們可以再加以過濾出某個日期範圍內的檔案? 
<br>
<br>
你先想一下，好好的想一 下.... :? 
<br>
<br>
你不知道，我也不知道， :roll: 
<br>
這個問題可能已經超出光靠DOS Batch語法就能完成的事情了。 
<br>
<br>
還是再問一次，有沒有可能改為規範遠端檔案伺服器上檔案的命名方式，否則我想就只有老老實實去寫程式來處理會比較快。 
<br>
<br>
當問題複雜到一個程度時，還是真得要寫個程式來執行這個任務。(如何寫這個程式我就不在這邊討論，可以參考[url]http://www.andowson.com/posts/list/199.page[/url]) 
<br>
<br>]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/1195.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/1195.page</link>
				<pubDate><![CDATA[Wed, 11 Jan 2012 19:49:51]]> GMT</pubDate>
				<author><![CDATA[ andowson]]></author>
			</item>
			<item>
				<title>回覆:[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ [quote=andowson]starzine您好: 
<br>
我給的範例確實是只能在本機端執行，取得本機端的檔案名稱，而您所需要的是取得遠端檔案伺服器目錄下的檔案清單。 
<br>
可以在sftp下執行目錄排序的指令如下(日期最近的會排在上面) 
<br>
ls -lt 
<br>
但接下來可能你會問要如何從psftp將這個指令的結果(目錄內的檔案清單)傳回，好讓我們可以再加以過濾出某個日期範圍內的檔案? 
<br>
<br>
你先想一下，好好的想一 下.... :? 
<br>
<br>
你不知道，我也不知道， :roll: 
<br>
這個問題可能已經超出光靠DOS Batch語法就能完成的事情了。 
<br>
<br>
還是再問一次，有沒有可能改為規範遠端檔案伺服器上檔案的命名方式，否則我想就只有老老實實去寫程式來處理會比較快。 
<br>
<br>
當問題複雜到一個程度時，還是真得要寫個程式來執行這個任務。(如何寫這個程式我就不在這邊討論，可以參考[url]http://www.andowson.com/posts/list/199.page[/url]) 
<br>
<br>
[/quote] 
<br>
<br>
[color=darkblue]大大您好： 
<br>
謝謝您的指教～ 
<br>
我想，這的確是有點難，可能需要寫程式來解決... 
<br>
我來另外想辦法好了，謝謝您囉！ 
<br>
有機會再請教！ :lol:[/color]]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/1196.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/1196.page</link>
				<pubDate><![CDATA[Thu, 12 Jan 2012 11:03:13]]> GMT</pubDate>
				<author><![CDATA[ starzine]]></author>
			</item>
			<item>
				<title>[Windows]如何定時自動備份整個網站目錄到遠端伺服器</title>
				<description><![CDATA[ <br>
請教可有 .. (and Thanks) 
<br>
<br>
.bat 計算檔案大小 
<br>
<br>
條件： 
<br>
1. 可計算超過 2147483647 (2 GB)數字 (可能用到 PowerShell) 
<br>
2. 希望用變數定義, 磁區, 路徑, 檔案形態 
<br>
<br>
　(例) 
<br>
　(1) D:\*.*/s (D: 所有) 
<br>
　(2) D:\*.rar/s (D: 所有 .rar) 
<br>
　(3) D:\*.mp4 *.mkv *.avi ... (D: 影片檔) 
<br>]]></description>
				<guid isPermaLink="true">https://forum.andowson.com/posts/preList/42/1419.page</guid>
				<link>https://forum.andowson.com/posts/preList/42/1419.page</link>
				<pubDate><![CDATA[Sat, 24 Mar 2018 15:23:56]]> GMT</pubDate>
				<author><![CDATA[ jown00]]></author>
			</item>
	</channel>
</rss>