檔案檢查 搭配 Mail通知(BY VBS)~~主程式介紹
目的
最近公司外商的資料要轉入,商討之下,讓對方使用FTP上傳資料,因為是晚上十一點過後了,要等到這時候檢查對方是否有上傳成功,我看有點困難,科技使終來自人性是吧,所以寫了以下的VBS。
架構
程式
DOS::
@echo off
REM 設定檔案名稱
set Sa=SA%date:~2,2%%date:~5,2%%date:~8,2%_0016.txt
set e1=e1%date:~2,2%%date:~5,2%%date:~8,2%_0016.txt
set et=et%date:~2,2%%date:~5,2%%date:~8,2%_0016.txt
set ep=ep%date:~2,2%%date:~5,2%%date:~8,2%_0016.txt
set ef=ef%date:~2,2%%date:~5,2%%date:~8,2%_0016.txt
REM 呼叫VBS程式,後面給序參數
cscript do_File_Check.vbs %saj% %e01% %eti% %epi% %efi%
if %ERRORLEVEL% EQU 0 goto End
if %ERRORLEVEL% EQU 1 goto Mail
:Mail
cscript do_Mail_Send.vbs
goto End
:End
VBS::
do_File_Check.vbs
Dim conf_file(5),conf_file_path(5),check_File_Add
Dim flag,MainPath,file_name,Newfso,fso
flag=0
today = Date
name = Year(Today) & Month(Today) & Day(Today)
'呼叫副函式
call Pathset
'建立物件(針對檔案處理的物件)
Set fso=CreateObject("Scripting.FileSystemObject")
'建立檔案
file_name = MainPath & name & ".txt"
Set Newfso = fso.CreateTextFile(file_name,True)
call Filexit
'關閉檔案
Newfso.Close
If flag=0 Then
fso.DeleteFile file_name
WScript.Quit 0
else
WScript.Quit 1
end if
Set fso = Nothing
sub Pathset
'將DOS上傳來的參數放入Arry中
Set cmdArray = WScript.Arguments
'此是取得此檔案的完整路徑+檔名
ScriptFullName = WScript.ScriptFullName
'此是取得此檔案的檔名
ScriptName = WScript.ScriptName
'此是將完整路徑和檔名分開,僅取用完整路徑即可
MainPath = Replace(ScriptFullName,ScriptName,"")
i=0
Do While i < 5
'一一的將完整路徑+傳入的參數存入陣列當中
conf_file_path(i) = MainPath & cmdArray(i)
i=i+1
Loop
end sub
sub Filexit
Newfso.WriteLine("以下為" & name & "時,沒有傳上來的檔案:")
i=0
Do While i < 5
'檢查檔案是否存在
If Not fso.FileExists(conf_file_path(i)) Then
'WScript.echo "[" & conf_file(i) & "] not found."
Newfso.WriteLine("[" & conf_file(i) & "] not found.")
flag=1
end if
i=i+1
Loop
end subdo_Mail_Send.vbs
dim flag,ScriptFullName,ScriptName,MainPath,file_name
today = Date
name = Year(Today) & Month(Today) & Day(Today)
set Fso = createobject("Scripting.FileSystemObject")
call Pathset
if not fso.FileExists(file_name) then
flag = 0
call sendmail
Else
flag = 1
call sendmail
end if
sub Pathset
ScriptFullName = WScript.ScriptFullName
ScriptName = WScript.ScriptName
MainPath = Replace(ScriptFullName,ScriptName,"")
file_name = MainPath & name & ".txt"
end sub
sub sendmail
'建立CDO的物件
set msg = WScript.CreateObject("CDO.Message")
' 以下為CDO的參數值
msg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
msg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
msg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "SMTP Server"
msg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
msg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "User"
msg.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "Password"
'msg.Configuration.Fields.Item(schema & "smtpusessl") = 1
msg.From = "Sender name"
msg.To = "Receiver mail"
msg.Subject = "轉檔失敗"
if flag = 1 then
msg.TextBody = "如附件。(測試信件)"
'可附件附件檔
msg.AddAttachment file_name
else
msg.TextBody = "轉檔失敗,但並沒有產生錯誤文件,需檢查問題。"
end if
msg.Configuration.Fields.Update
msg.Send
end sub
補充說明
檔案檢查 搭配 Mail通知(BY VBS)的詳細解譯...《cooming soon》...
0 個意見:
張貼留言
訂閱 張貼留言 [Atom]
<< 首頁