|
-
Jan 29th, 2012, 12:20 PM
#1
Thread Starter
Hyperactive Member
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
Last edited by intraman; Jan 29th, 2012 at 12:28 PM.
-
Jan 29th, 2012, 12:52 PM
#2
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
-
Jan 29th, 2012, 12:55 PM
#3
Thread Starter
Hyperactive Member
Re: Strange socket problem using FTP stream
 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.
-
Jan 29th, 2012, 01:08 PM
#4
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.
Last edited by BlindSniper; Jan 29th, 2012 at 01:10 PM.
Reason: stat mistake
-
Jan 29th, 2012, 01:21 PM
#5
Thread Starter
Hyperactive Member
Re: Strange socket problem using FTP stream
 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.
-
Jan 29th, 2012, 02:48 PM
#6
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.
-
Jan 30th, 2012, 01:39 AM
#7
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?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|