Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using FTP and clearing out memory
Message
From
25/04/2013 13:56:13
 
 
To
All
General information
Forum:
ASP.NET
Category:
Other
Title:
Using FTP and clearing out memory
Environment versions
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01571897
Message ID:
01571897
Views:
74
I have a client application which makes use of my FTP class like this:
        Dim loFTP As Framework.Framework.FTP = New Framework.Framework.FTP(oApp)

        ' For each record
        For lnCounter = 0 To loData.nCount - 1
            loRow = loData.oRows(lnCounter)

            ' Initiate FTP settings
            loFTP.cHost = lcHost
            loFTP.cUsername = Trim(loRow("Username"))
            loFTP.cPassword = Trim(loRow("Password"))
            loFTP.cRemoteDirectory = "Accounting/Received"

            ' If we cannot get the directory
            If Not loFTP.GetDirectory() Then
            End If

        Next
This is done in a loop. So, every minute, a robot executes this task by creating a reference to loFTP. loFTP is used in the loop, a For\Next, but the parameters are changing for various directory listings that I have to get. However, I do not recreate loFTP every time, only every minute when the robot processes its pending work.

I am facing a situation that sometimes, we cannot process this code anymore. At first, I thought it was the other end that was not online, a bad Internet connection or the FTP server was down for maintenance. But, they confirmed us that it was up and running. So, I got errors like unable to connect and so on.

So, I am concluding that I could recreate my loFTP at every For\Next loop such as:
        Dim loFTP As Framework.Framework.FTP = Nothing

        ' For each record
        For lnCounter = 0 To loData.nCount - 1
            loRow = loData.oRows(lnCounter)

            loFTP = New Framework.Framework.FTP(oApp)

            ' Initiate FTP settings
            loFTP.cHost = lcHost
            loFTP.cUsername = Trim(loRow("Username"))
            loFTP.cPassword = Trim(loRow("Password"))
            loFTP.cRemoteDirectory = "Accounting/Received"

            ' If we cannot get the directory
            If Not loFTP.GetDirectory() Then
            End If

        Next
This seems to be a better approach to eliminate memory leak by using too heavily loFTP from within one declaration.

But, if I do this, I would have to adjust a bunch of places everywhere. I would have wanted to fix that at the framework level in the FTP class. Anyone would know for example what kind of memory cleanup or reset of the class object I could do in the GetDirectory() method to make sure that everything is clean after a process?

The GetDirectory() method is using things like these:
                ' URI
                lcURI = lcServerType + "://" + cHost + lcPort + "/" + lcDrive + cRemoteDirectory

                ' For each retry
                For lnCounter = 1 To lnRetry

                    ' Reset the values
                    cMessage = ""

                    Try

                        ' FTP setup
                        loFtpWebRequest = System.Net.FtpWebRequest.Create(New Uri(lcURI))
                        loFtpWebRequest.Credentials = New System.Net.NetworkCredential(cUsername, cPassword)
                        loFtpWebRequest.Method = System.Net.WebRequestMethods.Ftp.ListDirectoryDetails

                        ' If we use FTP/SSL  (AUTH SSL)
                        If nNoFTPProtocol = 2 Then
                            loFtpWebRequest.EnableSsl = True
                        End If

                        loFtpWebResponse = loFtpWebRequest.GetResponse()

                        loStreamReader = New StreamReader(loFtpWebResponse.GetResponseStream())

                        ' Load the files into the string builder
                        loStringBuilder.LoadString(loStreamReader.ReadToEnd())
Could there be something in FtpWebRequest I could call as a method to clear something in memory? ...as well as FtpWebResponse
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Next
Reply
Map
View

Click here to load this message in the networking platform