コマンドファイルを作成してftp.exeに渡すという手もあるけど、まずはWSHのみでダウンロードするサンプル。
列挙されるアイテムは全てファイルという前提になってます。フォルダがある場合は想定していません。
列挙されるアイテムは全てファイルという前提になってます。フォルダがある場合は想定していません。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<job> | |
<script> | |
fs = new ActiveXObject('Scripting.FileSystemObject') | |
Write = function(path,v){with(fs.CreateTextFile(path)){Write(v);Close()}} | |
Write8 = function(path,v){with(fs.OpenTextFile(path,8,true)){Write(v);Close()}} | |
d = new Date() | |
二桁 = function(v){var t='0'+v, L=t.length; return t.slice(L-2,L)} | |
path = fs.GetAbsolutePathName([d.getFullYear(),二桁(d.getMonth()+1),二桁(d.getDate())].join('-')) | |
if(!fs.FolderExists(path)){fs.createFolder(path)} | |
// FTP接続でパラメータファイルをダウンロードする | |
shell = new ActiveXObject('Shell.Application') | |
remoteF = shell.NameSpace('ftp://USER:PASSWORD@192.168.250.1/home/parameter') | |
localF = shell.NameSpace(path) | |
for(i=0,L=remoteF.items().count; i<L ;i++){ | |
アイテム = remoteF.items().item(i) | |
名前 = アイテム.Name | |
サイズ = アイテム.Size | |
localF.copyHere(アイテム) | |
カウント = 0 | |
// localに「名前」のファイルが出来るまで待つループ | |
while(!fs.FileExists(path+'/'+名前)){ | |
WScript.Sleep(500) | |
if(++カウント>100){ | |
// 100回カウントしてもダメなら諦める | |
Write8(path+'/log.txt','timeout\t'+名前+'\r\n') | |
break | |
} | |
} | |
// ダメだった場合は次のファイルのトライに移る | |
if(!fs.FileExists(path+'/'+名前)){continue} | |
while(true){ | |
ファイル = fs.GetFile(path+'/'+名前) | |
if(ファイル.Size==サイズ){break} | |
if(++カウント>100){ | |
Write8(path+'/log.txt','timeout\t'+名前+'\tサイズ不足\r\n') | |
break | |
} | |
} | |
} | |
</script> | |
</job> |
0 件のコメント:
コメントを投稿