Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Studio
  4. How to download all latest files from ftp server to pc automatically in vb.net

How to download all latest files from ftp server to pc automatically in vb.net

Scheduled Pinned Locked Moved Visual Studio
sysadmincsharpphpdata-structures
2 Posts 2 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 12925239
    wrote on last edited by
    #1

    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.Threading

    Public 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

    L 1 Reply Last reply
    0
    • U User 12925239

      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.Threading

      Public 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

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups