Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using FTP and clearing out memory
Message
De
25/04/2013 19:38:56
 
 
À
25/04/2013 13:56:13
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
VB 9.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Divers
Thread ID:
01571897
Message ID:
01571935
Vues:
34
In C#, I would wrap it all in a using statement and garbage collection would be handled automatically. I'm not sure what the equivalent VB usage is.


>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
Craig Berntson
MCSD, Microsoft .Net MVP, Grape City Community Influencer
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform