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 NextThis 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.
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 NextThis seems to be a better approach to eliminate memory leak by using too heavily loFTP from within one declaration.
' 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