Imports System
Imports System.IO
Imports System.Web
Imports System.Net
Imports System.Net.WebClient
Imports System.Net.Configuration
Module Module1
Sub Main()
Dim date1 As New Date(2008, 8, 29, 19, 27, 15, 18) '
Dim date2 As String 'Sets date to string
date1 = Now() 'Sets date1 to now()
date1 = DateAdd(DateInterval.Day, -1, date1) 'Subtracts one day
date2 = (date1.ToString("yyyyMMdd")) 'Puts date in Aloha dated sub format
Dim StoreID As String
StoreID = My.Computer.FileSystem.ReadAllText("D:\VBS-AUTOCOPY\STOREID.INI") 'checks storeid.ini for store id
Console.WriteLine("Store ID: " & StoreID) 'writes out store id
For Each filetdx As String In IO.Directory.GetFiles("D:\Aloha\" & date2 & "\", "*.TDX") 'deletes tdx files
IO.File.Delete(filetdx)
Next
Console.WriteLine("Deleting TDX files.")
For Each filecdx As String In IO.Directory.GetFiles("D:\Aloha\" & date2 & "\", "*.CDX") 'deletes cdx files
IO.File.Delete(filecdx)
Next
Console.WriteLine("Deleting CDX files.")
My.Computer.FileSystem.CreateDirectory("D:\XFER\" & date2) 'creates a directory for xfer
Console.WriteLine("Created dated sub-dir for transfer.")
Try
My.Computer.FileSystem.CopyFile("D:\Aloha\EDC\FIFTH THIRD PROCESSING SOLUTIONS\" & date2 & ".stl", "D:\xfer\" & date2 & "\" & date2 & ".STL") 'copies STL file to Aloha dated-sub
My.Computer.FileSystem.CopyFile("D:\Aloha\EDC\edc.ini", "D:\xfer\" & date2 & "\EDC.INI") 'copies edc.ini to dated-sub
Console.WriteLine("Copied settlement file.")
Console.WriteLine("Copied EDC.INI")
Catch ex As Exception
Console.WriteLine("Copying of settlement file/EDC.INI failed.")
End Try
My.Computer.FileSystem.CopyDirectory("D:\aloha\" & date2, "D:\xfer\" & date2) 'copies all files to xfer dir
Console.WriteLine("Copied files to transfer directory successfully.")
Try
Dim NewZip As New ICSharpCode.SharpZipLib.Zip.FastZip 'zips up files
NewZip.CreateZip("D:\xfer\" & date2 & ".zip", "D:\xfer\" & date2, False, Nothing, Nothing)
Console.WriteLine("ZIP file created successfully.")
Catch ex As Exception
Console.WriteLine("ZIP file creation failed.")
MsgBox("ZIP File Creation Error! Call the Briad Helpdesk 602-567-5050", MsgBoxStyle.Critical)
End Try
Try
Console.WriteLine("Starting FTP transfer.")
Dim uriString As String = "ftp://10.100.1.80/" & StoreID & "/" & date2 & ".ZIP"
Dim myWebClient As New WebClient()
Dim DatedSub As String = "D:\XFER\" & date2 & ".ZIP"
Dim responseArray As Byte() = myWebClient.UploadFile(uriString, DatedSub)
Console.WriteLine("Upload completed successfully.")
Catch ex As Exception
Console.WriteLine("An error has occured while uploading the file.")
Console.WriteLine("No garbage collection has been performed.")
MsgBox("Please call the Helpdesk immediately! Upload failed.", MsgBoxStyle.Critical)
End Try
Try
Dim DirectoryToDelete2 As String
DirectoryToDelete2 = "d:\xfer\" & date2
If System.IO.Directory.Exists(DirectoryToDelete2) = True Then
System.IO.Directory.Delete(DirectoryToDelete2, True)
Console.WriteLine("Performing cleanup.")
Console.WriteLine("Backup folder delted.")
Else
If System.IO.Directory.Exists(DirectoryToDelete2) = False Then
Console.WriteLine("Could not find backup directory in D:\XFER.")
End If
End If
My.Computer.FileSystem.DeleteFile("d:\xfer\" & date2 & ".ZIP", FileIO.UIOption.OnlyErrorDialogs, FileIO.RecycleOption.DeletePermanently)
Console.WriteLine("Deleted transferred file.")
Console.WriteLine("Backup complete.")
Catch ex As Exception
Console.WriteLine("Garbage collection failed.")
Console.WriteLine("End of program.")
End Try
End Sub
End Module