Silentbob
Silentbob

Reputation: 3065

downloading a csv from ftp site using the webbrowser control

I have the following code.

Private Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
Do
    For i As Integer = 0 To Me.WebBrowser1.Document.Links.Count - 1
        If Me.WebBrowser1.Document.Links(i).InnerHtml.StartsWith("APX Power UK RPD historical data") Then
            Dim link As String
            link = Me.WebBrowser1.Document.Links(i).GetAttribute("href")

            WebBrowser2.Navigate(link)
            WebBrowser1.Dispose()

            Exit Do
        End If
    Next
Loop
End Sub

IT finds a link on a page and sends a click to it, this navigates to a ftp site.enter image description here

I want to download the file HH_Only_rpd.csv to c:/temp automatically.

I have been experimenting with webclient but I have hit a wall. I can navigate straight to the file using WebBrowser1.Navigate("ftp://ae.rpduser:[email protected]/HH_ONLY_rpd.csv") but I get a save as dialog box that I don't want as I need it all to be silent as I am going to automate it.

I am using VS 2013.

Upvotes: 0

Views: 605

Answers (2)

Silentbob
Silentbob

Reputation: 3065

after much research I used a console application with the following code.

Imports System.Net
Module Module1
    Sub Main()
        Try
            Dim wc As New WebClient
            wc.DownloadFile(New Uri("ftp://ae.rpduser:[email protected]/HH_ONLY_rpd.csv"), "c:\Temp\test.csv")
        Catch ex As Exception
        End Try
    End Sub
End Module

Upvotes: 0

CodeCaster
CodeCaster

Reputation: 151588

I need it all to be silent

Then use the FtpWebRequest class, not the WebBrowser control.

Upvotes: 2

Related Questions