I have the below program and it's working fine, the function of the program that it takes the IP address along with host name from the array and then pass it down by sub-string the IP/host name, and then it creates .ZIP file "using 3rd party library" on the remote machine and get the file transfer to a central server. My requirements which am stuck with:
How to make my program to pick up my computer list from .txt file instead of embedding it in the program, so if there's a new machine IP need to be added I just need to add it in .txt file
How I can make my process runs in parallel, since my program will run IP after IP in serial which takes longer time than executing all at once.
Code:
Imports System.IO
Module Module1
Dim RemoteComputer As New List(Of String)
Const FILENAME As String = "c:\temp\test.txt"
Sub Main()
Try
Dim reader As New StreamReader(FILENAME)
While reader.EndOfStream = False
RemoteComputer.Add(reader.ReadLine)
End While
For Each ComputerName In RemoteComputer
Dim IPAddress As String = ComputerName.ToString.Substring(0, 13).ToString()
Dim CName As String = ComputerName.ToString.Substring(14, 6).ToString()
Dim ZipToCreate As String = "\" & IPAddress & "\C$\temp\Test-" & CName & ".zip"
If My.Computer.Network.Ping(Trim(IPAddress.ToString())) Then
Using zip As ZipFile = New ZipFile
Dim filenames As String() = System.IO.Directory.GetFiles("\" & IPAddress & "\C$\Sample\")
For Each filename In filenames zip.AddFile(filename, "")
Next
zip.Save(ZipToCreate)
File.Copy("\" & IPAddress & "\C$\temp\Test-" & CName & ".zip", "\destSeverIP\C$\Temp\Test-" & CName & ".zip", True)
Console.WriteLine("File copied successfully.....")
End Using
Else : Console.WriteLine("Remote machine is not reachable")
End If
Next
Catch ex As Exception
Console.Error.WriteLine(ex.Message.ToString())
Finally
Console.ReadLine()
End Try
End Sub
End Module
<!-- language: vb.net -->and a newline after that again before the code block? Why is this suddenlycsscode? Why did you change the"\\"to"\"? It's correct in Visual Basic, it was supposed to access an SMB share with\\someIP\pathI guess.My.Computer.Network.Ping()call into atry-catchif it can throw exceptions. By the way, for the "executing things in parallel", you chould check outParallel.ForEach()(msdn.microsoft.com/de-de/library/…)