Results 1 to 7 of 7

Thread: Strange socket problem using FTP stream

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Location
    Manchester
    Posts
    266

    Angry 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.

  2. #2
    Fanatic Member BlindSniper's Avatar
    Join Date
    Jan 2011
    Location
    South Africa
    Posts
    865

    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

    Useful CodeBank Entries of mine
    Expand Function
    Code Compiler
    Sudoku Solver
    HotKeyHandler Class

    Read this to get Effective help on VBForums
    Hitchhiker's Guide to Getting Help at VBF

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Location
    Manchester
    Posts
    266

    Re: Strange socket problem using FTP stream

    Quote Originally Posted by BlindSniper View Post
    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.

  4. #4
    Fanatic Member BlindSniper's Avatar
    Join Date
    Jan 2011
    Location
    South Africa
    Posts
    865

    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

    Useful CodeBank Entries of mine
    Expand Function
    Code Compiler
    Sudoku Solver
    HotKeyHandler Class

    Read this to get Effective help on VBForums
    Hitchhiker's Guide to Getting Help at VBF

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2004
    Location
    Manchester
    Posts
    266

    Re: Strange socket problem using FTP stream

    Quote Originally Posted by BlindSniper View Post
    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.

  6. #6
    Fanatic Member BlindSniper's Avatar
    Join Date
    Jan 2011
    Location
    South Africa
    Posts
    865

    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.

    Useful CodeBank Entries of mine
    Expand Function
    Code Compiler
    Sudoku Solver
    HotKeyHandler Class

    Read this to get Effective help on VBForums
    Hitchhiker's Guide to Getting Help at VBF

  7. #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
  •  



Click Here to Expand Forum to Full Width