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. BUT I want to windows service detect each 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. BUT I want to windows service detect each 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, Posting the question three times only annoys people. Have you set "Allow service to interact with the desktop", if not your service may hang on the msgbox's.
-
Hi, Posting the question three times only annoys people. Have you set "Allow service to interact with the desktop", if not your service may hang on the msgbox's.
firstly i posted question in another forum, so one member suggested me to post question in vb forum. That's why i posted here. and window service is interacting with desktop. it is working fine only problem is that it is downloading only specif file when the service is started. i want to download each new uploaded file. I am not trying to annoy people. i have problem. pls help me
-
firstly i posted question in another forum, so one member suggested me to post question in vb forum. That's why i posted here. and window service is interacting with desktop. it is working fine only problem is that it is downloading only specif file when the service is started. i want to download each new uploaded file. I am not trying to annoy people. i have problem. pls help me
Member 12957775 wrote:
suggested me to post question in vb forum
Yes and what else were you told to do? Did you do either one? I would guess not as this is the same code with the exact same problem.
Member 12957775 wrote:
i have problem. pls help me
If you don't listen we are just wasting our time.
Speed of sound - 1100 ft/sec Speed of light - 186,000 mi/sec Speed of stupid - instantaneous.