FtpWebRequest Trying to insert all filenames in folder into sql table? <p>Using the following program I'm trying to insert all the filenames listed in a folder on ftp server into a SQL table.</p> <p>While Writing to table I'm getting an error </p> <blockquote> <p>c# cannot access a disposed object. object name 'system.net.sockets.networkstream'</p> </blockquote> <p><strong>reader.ReadToEnd()</strong> Writing the whole stream where I want one by one filename.</p> <pre><code>namespace Examples.System.Net { public class WebRequestGetExample { public static void Main() { FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://myftpaddress.com/0708/"); request.Method = WebRequestMethods.Ftp.ListDirectory; request.Credentials = new NetworkCredential("vish10", "MyPasswd"); FtpWebResponse response = (FtpWebResponse)request.GetResponse(); Stream responseStream = response.GetResponseStream(); StreamReader reader = new StreamReader(responseStream); Console.WriteLine(reader.ReadToEnd()); SqlConnection sqlConnection1 = new SqlConnection("Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=DMSTG;Data Source=."); SqlCommand cmd = new SqlCommand(); cmd.CommandText = @"Insert into FTPfileList0708Folder values('" + reader.ReadToEnd().ToString() + "')"; cmd.Connection = sqlConnection1; sqlConnection1.Open(); cmd.ExecuteNonQuery(); sqlConnection1.Close(); Console.WriteLine("Directory List Complete, status {0}", response.StatusDescription); reader.Close(); response.Close(); } } } </code></pre>