Strange socket problem using FTP stream
I am successfuly connecting to an FTP server and have no problems with uploading / downloading files and initiating general file transfers. However, when attempting to list the directory I get a strange exception and it seemed to just start happening of its own accord.
Cannot access a disposed object.
Object name: 'System.Net.Sockets.NetworkStream'.
This is confusing! I am certainly not manually disposing any of the connection of stream reader objects, nor am I disposing anything else in this entire sub routine. On setting breakpoints, it seems that the array list is filled correctly but then the error fires when the status code is 226 despite me clearly specifying that the while loop should not run under these circumstances. (226 is equal to FtpStatusCode.ClosingData)
Any help would be really appreciated. I am stumped. :(
http://pastebin.com/dXN96ZuA
Re: Strange socket problem using FTP stream
I don't actually know why you are having your error, but I might have a possible workaround. Use the streamreader to read everything at once and then using string.split(vbnewline) you should get the array you are looking for
Re: Strange socket problem using FTP stream
Quote:
Originally Posted by
BlindSniper
I don't actually know why you are having your error, but I might have a possible workaround. Use the streamreader to read everything at once and then using string.split(vbnewline) you should get the array you are looking for
Blindsniper,
Yeah, that is one way to workaround. However, i'm a bit nervous about this as there could be alot of data coming back. (12000 + strings) and I don't want to trigger a variable overload. It's all very mysterious.
Re: Strange socket problem using FTP stream
Well, you are just as likely to cause one with your current method as with the workaround. one single string can hold 1 billion characters(2 gig ram) and one array can hold 2.14 billion elements(if not more), so the real limitation is your RAM.
Re: Strange socket problem using FTP stream
Quote:
Originally Posted by
BlindSniper
Well, you are just as likely to cause one with your current method as with the workaround. one single string can hold 1 billion characters(2 gig ram) and one array can hold 2.14 billion elements(if not more), so the real limitation is your RAM.
A point well made. I suppose it just annoys me that this error is occurring and quite honestly, it looks to me like a long-standing bug. It's not great practice to load so much data into one string as you know. However, it seems like the only choice.
Re: Strange socket problem using FTP stream
I would like the opinion of some of the expert programmers on why this is happening, but all I can think of that there is some kind of subtle error you are overlooking in the while statement and maybe changing the And's to AndAlso's would help and instead of using a ArrayList, use a List(of string), but I can't see how these changes would solve the problem.
Re: Strange socket problem using FTP stream
Try converting some of the And's to AndAlso's, that would help out some. I'm not sure why else as I'm not too familiar with this part of .NET...maybe the connection gets terminated and the stream disposes itself?