troubleshooting Question

VB.NET FTP problem.. get same file all the time?

Avatar of kavvis
kavvis asked on
.NET ProgrammingMicrosoft Development
7 Comments1 Solution335 ViewsLast Modified:
Hi I have some problem whit some code...

When I run this code it works perfect the first time every time the application runs..
But the next time it get´s the same "old file" as it took the first time.. I think I don´t do a proper "close ftp" but can´t figure out what I do wrong.

If I close the application down and then start it then it works...
The problem is it only get the file one time..

Please give me some help..
''' <summary>
    ''' Get FTP
    ''' </summary>
    ''' <remarks></remarks>
    Private Sub Download_Files()

            Dim INet, INetConn As Integer
            ' Kontrollbit visa hämtning ok osv..
            Dim RC As Boolean

            'Skapar FTP-communicationen FTPAdress
            INet = InternetOpen("FTP Connection", 1, vbNullString, vbNullString, 0)
            INetConn = InternetConnect(INet, FTPAdress, 21, "test", "test", 1, 0, 0)

            'Filer som skall hämtas..
            LARMFile = "test1.csv"
            ' Trendfil som skall hämtas
            RC = FtpGetFile(INetConn, "/TRENDS/test1.SKV", TempFiles + NewFile, False, 1, 0, 0)
            ' Trendfil som skall hämtas
            LARMFile2 = "test2.csv"
            FtpGetFile(INetConn, "/TRENDS/test2.SKV", TempFiles + NewFile2, False, 1, 0, 0)


            ' Show if get have been correct
            If RC Then
                Me.uxStatus.Text = "bla bla bla successfully!"
            End If
            'Close the FTP communicationen...

            ' Set the new file adress
            Dim fFile As New FileInfo(TempFiles + NewFile)
            If Not fFile.Exists Then
                ' MessageBox.Show("No file exits")

                Dim aa As Long
                aa = GetAttr(TempFiles + NewFile)
                Debug.Print("before=" & aa)
                aa = (aa And 127) Xor vbReadOnly
                Debug.Print("set to " & aa)
                SetAttr(TempFiles + NewFile, aa)
                aa = GetAttr(TempFiles + NewFile)
                Debug.Print("after=" & aa)
            End If

            ' Sätter filens adress
            Dim fFile3 As New FileInfo(TempFiles + NewFile2)
            If Not fFile3.Exists Then
                ' MessageBox.Show("Finns ingen fil...")

                Dim aa As Long
                aa = GetAttr(TempFiles + NewFile2)
                Debug.Print("before=" & aa)
                aa = (aa And 127) Xor vbReadOnly
                Debug.Print("set to " & aa)
                SetAttr(TempFiles + NewFile2, aa)
                aa = GetAttr(TempFiles + NewFile2)
                Debug.Print("after=" & aa)
            End If

        Catch ex As Exception
            Me.uxStatus.Text = "FTP-Failed"
        End Try

    End Sub
Join our community to see this answer!
Unlock 1 Answer and 7 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 7 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros