Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using FTP and clearing out memory
Message
From
25/04/2013 16:36:59
 
 
To
25/04/2013 15:30:25
General information
Forum:
ASP.NET
Category:
Other
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:
01571917
Views:
80
This message has been marked as the solution to the initial question of the thread.
>>I was going to suggest something similar
>>
>>In addition to Disposing of the StreamReader, I think you need to do the same for
>>
>>
>>loFtpWebResponse.GetResponseStream()  // the stream
>>loFtpWebResponse 
>>
>
>Isn't loFtpWebResponse.GetResponseStream() already part of the Using?

Yes - but that is to Dispose() of loStreamReader




>
>>In addition, could you reuse the following (rather than instantiating each time)
>>
>>New Uri(lcURI)
>>New System.Net.NetworkCredential(cUsername, cPassword)
>>
>
>This, I do not understand. Are you saying I could get rid of the New in each of those two lines?


Yes

something like
			// this part outside the loop - even at class level if possible

			Uri uri = new Uri(lcURI);
			NetworkCredential credentials = new System.Net.NetworkCredential(cUsername, cPassword);
			// end part outside the loop

			// FTP setup
			var loFtpWebRequest = System.Net.FtpWebRequest.Create(uri);
			loFtpWebRequest.Credentials = credentials;
			loFtpWebRequest.Method = System.Net.WebRequestMethods.Ftp.ListDirectoryDetails;

			// If we use FTP/SSL  (AUTH SSL)
			// If ( nNoFTPProtocol == 2) 
			//     loFtpWebRequest.EnableSsl = true;
            

			using ( var loFtpWebResponse = loFtpWebRequest.GetResponse() )
			{
				using ( var s = loFtpWebResponse.GetResponseStream())
				{
					using( var loStreamReader = new StreamReader(s) )
					{
           
						// Load the files into the string builder
						loStringBuilder.LoadString(loStreamReader.ReadToEnd());
					}
				}
			}

		}
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform