How to download all latest files from ftp server to pc automatically in vb.net
-
Hi folks,
I am new to vb. I need help to create a vb.net windows service to download latest new uploaded files from server after every 1 minute to local computer . This code download same only single file once the service started
I want to service detect the latest new file uploaded on server and download it automatically. Below is my code. Kindly help me.
Imports System
Imports System.IO
Imports System.Net
Imports System.Timers
Imports System.ThreadingPublic Class Service1
Dim timerSchedule As System.Timers.Timer Protected Overrides Sub OnStart(ByVal args() As String) ' MyThread = New Threading.Thread(AddressOf Execute) timerSchedule = New System.Timers.Timer(1000) AddHandler timerSchedule.Elapsed, AddressOf timerSchedule\_Elapsed timerSchedule.Start() End Sub Protected Overrides Sub OnStop() End Sub Private Sub timerSchedule\_Elapsed(ByVal pSender As Object, ByVal pArgs As System.Timers.ElapsedEventArgs) Try timerSchedule.Stop() 'call my a function to do the scheduled task FTPDownloadFile() Catch ex As Exception Finally timerSchedule.Start() End Try End Sub Private Sub FTPDownloadFile() Dim ftpuri As String = "" Dim downloadpath As String = "" Dim ftpusername As String = "" Dim ftppassword As String = "" 'Create a WebClient. Dim request As New WebClient() ' Confirm the Network credentials based on the user name and password passed in. request.Credentials = New NetworkCredential("root", "") 'Read the file data into a Byte array Dim bytes() As Byte = request.DownloadData("http://localhost/salary\_system/") Try ' Create a FileStream to read the file into For Each i As String In downloadpath Dim DownloadStream As FileStream = IO.File.Create("C:\\download\\\*.php") ' Stream this data into the file DownloadStream.Write(bytes, 0, bytes.Length) ' Close the FileStream DownloadStream.Close() Next Catch ex As Exception MsgBox(ex.Message) Exit Sub End Try MsgBox("Process Complete") End Sub
End Class
-
Hi folks,
I am new to vb. I need help to create a vb.net windows service to download latest new uploaded files from server after every 1 minute to local computer . This code download same only single file once the service started
I want to service detect the latest new file uploaded on server and download it automatically. Below is my code. Kindly help me.
Imports System
Imports System.IO
Imports System.Net
Imports System.Timers
Imports System.ThreadingPublic Class Service1
Dim timerSchedule As System.Timers.Timer Protected Overrides Sub OnStart(ByVal args() As String) ' MyThread = New Threading.Thread(AddressOf Execute) timerSchedule = New System.Timers.Timer(1000) AddHandler timerSchedule.Elapsed, AddressOf timerSchedule\_Elapsed timerSchedule.Start() End Sub Protected Overrides Sub OnStop() End Sub Private Sub timerSchedule\_Elapsed(ByVal pSender As Object, ByVal pArgs As System.Timers.ElapsedEventArgs) Try timerSchedule.Stop() 'call my a function to do the scheduled task FTPDownloadFile() Catch ex As Exception Finally timerSchedule.Start() End Try End Sub Private Sub FTPDownloadFile() Dim ftpuri As String = "" Dim downloadpath As String = "" Dim ftpusername As String = "" Dim ftppassword As String = "" 'Create a WebClient. Dim request As New WebClient() ' Confirm the Network credentials based on the user name and password passed in. request.Credentials = New NetworkCredential("root", "") 'Read the file data into a Byte array Dim bytes() As Byte = request.DownloadData("http://localhost/salary\_system/") Try ' Create a FileStream to read the file into For Each i As String In downloadpath Dim DownloadStream As FileStream = IO.File.Create("C:\\download\\\*.php") ' Stream this data into the file DownloadStream.Write(bytes, 0, bytes.Length) ' Close the FileStream DownloadStream.Close() Next Catch ex As Exception MsgBox(ex.Message) Exit Sub End Try MsgBox("Process Complete") End Sub
End Class
Member 12957775 wrote:
download same only single file
Hmmm... okay if it does, and I don't see how it could, it's because
Member 12957775 wrote:
Dim downloadpath As String = ""
Member 12957775 wrote:
For Each i As String In downloadpath
Your download path is empty. Learning how to use the debugger is a valuable skill, You need to develop that skill. As well as posting your question in the appropriate forum. Your question has nothing to do with Visual Studio and would be better answered in the Visual Basic forum.
Speed of sound - 1100 ft/sec Speed of light - 186,000 mi/sec Speed of stupid - instantaneous.