'Author: Brian Wuchner 'Date: 1/18/2008 'FTP files and send status report if any are found to be less than 5KB errTo = "ftpnotify@sboa.in.gov" errSubject = "SBoA - File Transfer Report" errHTML = "The following files were detected as being less than 5KB on the SBoA FTP site.
" PDFSentFolder = "\\iotfilp50pw.shared.state.in.us\sboa\Audits\WebReports\sent" On Error Resume Next Set fso = CreateObject("Scripting.FileSystemObject") Set sh = CreateObject("Wscript.Shell") 'Attempt to delete any files that might remain on the FTP servers pre upload transferFromFolder = Replace(PDFSentFolder,"\sent","") Set inFolder = fso.GetFolder(transferFromFolder) Set deleteScriptOutFile = fso.CreateTextFile("sboa-delete.ftp",True) deleteScriptOutFile.WriteLine "open ftppublish.ai.org" deleteScriptOutFile.WriteLine "user lbaker 9cy87c" deleteScriptOutFile.WriteLine "cd sboa/WebReports" For Each file In inFolder.Files If InStr(LCase(file),".pdf") Then deleteScriptOutFile.WriteLine "delete " & replace(file,transferFromFolder & "\","") End if Next deleteScriptOutFile.WriteLine "disconnect" deleteScriptOutFile.WriteLine "bye" deleteScriptOutFile.Close Set deleteScriptOutFile = Nothing Set FTPDeleteTemp = sh.Exec("ftp -n -i -s:sboa-delete.ftp") deletes = FTPDeleteTemp.StdOut.ReadAll 'WScript.Echo deletes 'Run the FTP Transfer Set FtpTransferTemp = sh.Exec("sboa.bat") TransferResult = FtpTransferTemp.StdOut.ReadAll 'Count the number of files in the SMB Folder Set SentFolder = fso.GetFolder(PDFSentFolder) For each File in SentFolder.Files If InStr(lcase(file),".pdf") Then PDFSMBCount = PDFSMBCount + 1 End If Next 'Get a directory listing of pdf's in the FTP site Set FTPTemp = sh.Exec("ftp -n -i -s:sboa-dir.ftp") arrFtpDirList = split(FTPTemp.StdOut.ReadAll,vbCr) 'Count the number of PDF's on the FTP site 'Find any less than 5KB and add their information to the errHTML variable PDFFTPCount = 0 For FtpFile = 0 to UBound(arrFtpDirList) line = arrFtpDirList(FtpFile) If InStr(lcase(line),".pdf") Then PDFFTPCount = PDFFTPCount + 1 'filesize = Mid (line, 30, 13) filesize = Mid (line, 31, 13) If Trim(filesize) < 5119 Then errHTML = errHTML & "" & filesize & "byte file located at " & line & "
" End If End If Next errHTML = errHTML & "
A total of " & PDFFTPCount & " PDF's were found on the FTP site.
" errHTML = errHTML & "A total of " & PDFSMBCount & " PDF's were found in the sent folder. " & PDFSentFolder & ".
" If PDFSMBCount <> PDFFTPCount Then errHTML = errHTML & "An un-equal number of .pdf's were located." End If 'Send email if an error is detected (determined by a .pdf file being listed in the errHTML variable) If InStr(errHTML,".pdf") Then SendEmail errTo, errSubject, errHTML End If Sub SendEmail(strTo, strSubject, strBody) Set objEmail = CreateObject("CDO.Message") objEmail.From = "ftpnotify@sboa.IN.gov" objEmail.To = strTo objEmail.Subject = strSubject objEmail.HTMLBody = strBody objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mailrelay.iot.in.gov" objEmail.Configuration.Fields.Item _ ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25 objEmail.Configuration.Fields.Update objEmail.Send End Sub