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 Basic
  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 Basic
sysadmincsharpphpdata-structures
4 Posts 3 Posters 0 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. 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.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

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

      M Offline
      M Offline
      Michael_Davies
      wrote on last edited by
      #2

      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.

      U 1 Reply Last reply
      0
      • M Michael_Davies

        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.

        U Offline
        U Offline
        User 12925239
        wrote on last edited by
        #3

        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

        L 1 Reply Last reply
        0
        • U User 12925239

          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

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

          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.

          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