FTPコマンドファイルを作成して、FTP起動オプションでそのファイルを指定して処理してもらうサンプル。
転送を自動化した場合、コマンドファイルをいくつか抜き取り確認して内容に問題が無いか見るときなどに使用する。
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') | |
Read = function(p){try{var r=fs.OpenTextFile(p),v=r.ReadAll();r.Close();return v}catch(e){alert('Read Err.\n'+p)}} | |
path = fs.GetSpecialFolder(2) + '/' + fs.GetTempName() + '.ftp' | |
cmd = [ | |
'open 192.168.1.1', | |
'USER', | |
'PASSWORD', | |
'binary', | |
'cd /var/www/doc', | |
'lcd "\\\\PC1\\ABC"', | |
'put ABCDE.csv', | |
'quote site chmod 755 ABCDE.csv', | |
'close', | |
'bye' | |
].join('\r\n') | |
ws = fs.CreateTextFile(path) | |
ws.Write(cmd) | |
ws.Close() | |
// ファイルの内容が出力内容と一致するまで待たないと、コマンドファイルが中途半端な状態で次の処理に進んでしまう場合があるので | |
// 内容が一致するまでループする。 | |
while(true){ | |
WScript.Sleep(1000) | |
if(Read(path)==cmd){break} | |
} | |
shell = new ActiveXObject('WScript.Shell') | |
shell.Run('%windir%/system32/ftp -s:"' + path + '"' , 0) | |
</script> | |
</job> |
0 件のコメント:
コメントを投稿