pezzmedina pezzmedina - 1 year ago 76 Question

read all files in ftp and compare them to an access database to discard the files that i used

As you can see in the title it could be a little difficult to answer this question but i really need help

My.Computer.Network.DownloadFile("", "C:\Users\User\Desktop\base\Folder\filename.txt", "user", "password")

this is how i been doing the download of a file from a ftp server but i realize that what i do is wrong because the filename changes every 10 minutes that is why i need save the filename into access to make later a comparation and discard the files that are checked in my access table

i don´t know how can i save the filename from the ftp server to use as a variable or read all the filenames in the ftp server of course that i don´t want all the solution but a good start or advice will be great !!!

Answer Source

the only way that can i find was this i hope it could be helpful for someone

basically what i do is make a listdirectory and then pass the information into a listbox and then select the last item to save the filename finally i use as a variable for the download process this is not the best solution but it fit very well in my needs

Dim Dirlist As New List(Of String) 
    Dim request As FtpWebRequest = DirectCast(WebRequest.Create("ftp://server/folder/subfolder"), FtpWebRequest)
    Dim response = DirectCast(request.GetResponse(), FtpWebResponse)
    Dim responseStream As Stream = response.GetResponseStream
    request.Method = WebRequestMethods.Ftp.ListDirectory
    request.Credentials = New NetworkCredential("user", "pass")
    Using reader As New StreamReader(responseStream)
        Do While reader.Peek <> -1
        If ListBox1.Items.Count > 0 Then
            ListBox1.SelectedIndex = ListBox1.Items.Count - 1
        End If
    End Using
    Dim varia1 As String
    varia1 = ListBox1.SelectedItem.ToString
    Dim varia2 As String = "C:\localpath\"folder\subfolder
    Dim ftp1 As String = "ftp://server/folder/subfolder"
    Dim varia3 As String = varia2 + varia1
    Dim varia4 As String = ftp1 + varia1
    My.Computer.Network.DownloadFile(varia3, varia4, "user", "pass")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download