views:

17

answers:

0

Hello,

I am trying to download a file from an ftp site only if it's newer than my local file. Can anyone help how to incorporate to check for the file properties? right now it downloads the file, but just need if newer. The purpose is to update a .mdb with the contents of the file, so don't want to download file and run an update everytime my app runs, only if the file is different. This is the code I am using:

        Const localFile As String = "C:\version.xml"
    Const remoteFile As String = "/version.xml"
    Const host As String = "ftp://1.1.1.1"
    Const username As String = "user"
    Const password As String = "pwd"

    Dim URI As String = host & remoteFile
    Dim ftp As System.Net.FtpWebRequest = _
        CType(FtpWebRequest.Create(URI), FtpWebRequest)

    ftp.Credentials = New  _
        System.Net.NetworkCredential(username, password)

    ftp.KeepAlive = False

    ftp.UseBinary = True

    ftp.Method = System.Net.WebRequestMethods.Ftp.DownloadFile

    Using response As System.Net.FtpWebResponse = _
          CType(ftp.GetResponse, System.Net.FtpWebResponse)
        Using responseStream As IO.Stream = response.GetResponseStream

            Using fs As New IO.FileStream(localFile, IO.FileMode.Create)
                Dim buffer(2047) As Byte
                Dim read As Integer = 0
                Do
                    read = responseStream.Read(buffer, 0, buffer.Length)
                    fs.Write(buffer, 0, read)
                Loop Until read = 0
                responseStream.Close()
                fs.Flush()
                fs.Close()
            End Using
            responseStream.Close()
        End Using
        response.Close()
    End Using

Any help is appreciated