19 comments on “FTP Endeavor in WinRT – I

  1. Pingback: FTP Endeavor II – Upload and Download Files | Can Bilgin

  2. Hi , maybe someone could help me. I add the dll to my project and I tried to download(read) one file from ftp. You can see a part of my code,

    (…)
    var ftpClient = CreateFtpClient();

    await ftpClient.ConnectAsync();

    if (!ftpClient.IsConnected)
    {
    System.Diagnostics.Debug.WriteLine(“No connection could be made to the FTP server {0}:{1}”, m_Host, “21”);
    }
    else
    {

    string workDir = await ftpClient.GetWorkingDirectoryAsync();

    var fileFromFtp = await ftpClient.RetrieveFileAsync(“/” + fileFullPath);
    }
    (…)

    My application connect to the server with no problem, i can list all files, but when I try to read a file I am getting error that the object has been close. Errors below. Could anyone tell me what I am doing wrong (I would like to use storagefile)

    Error:
    A first chance exception of type ‘System.ObjectDisposedException’ occurred in mscorlib.ni.dll
    The thread 0xff0 has exited with code 259 (0x103).
    The thread 0xfe8 has exited with code 259 (0x103).
    The thread 0xf90 has exited with code 0 (0x0).
    The thread 0xf98 has exited with code 0 (0x0).
    The object has been closed. (Exception from HRESULT: 0x80000013)

    Thanks a lot!

    Like

    • i ended up on the same problem. somewhen the server connection runs into a timeout or something like that. but even keepalive did not improve it. Did you get a solution?

      Like

    • that is a good question… I will try to put together a sample for UWP… I don’t see a reason why not… also am planning to create a nuget package for this library…will announce here as soon as ready.

      Like

      • hi Can.. yes it works quite well for directory listing. but on files above 2 or 5 MB (jpg pictures from smartphones) after a while the error happens and download crashes.
        readBuffer = await stream.ReadAsync(buffer, bufferSize, InputStreamOptions.Partial)

        Error:
        A first chance exception of type ‘System.ObjectDisposedException’

        actual code
        readBuffer = await stream.ReadAsync(buffer, bufferSize, InputStreamOptions.Partial);
        iLoop = iLoop + 1;
        downloaded = resultingBuffer.Length;
        //—-
        if (readBuffer.Length == 0)
        {
        //
        fl_Sys_Messagebox(“readbuffer.length==0”, “IsEOF”);
        IsEOF = true;
        break; //to reload
        //
        }
        else if(readBuffer.Length < bufferSize)
        {
        //
        System.Diagnostics.Debug.WriteLine(“buffer to End: ” + downloaded);
        //
        }
        //—-
        resultingBuffer = resultingBuffer.Concat(readBuffer.ToArray()).ToArray();

        System.Diagnostics.Debug.WriteLine(iLoop + ” buffer:” + downloaded);

        if (iLoop % 300 == 0)
        {
        System.Diagnostics.Debug.WriteLine(iLoop + ” keepalive”);
        KeepAlive();
        }

        Like

      • Hi
        I have this problem in release version of app also with ftp in my local network on another machine with file of 50 mb.
        I use exactly your code in my uwp app. Are you sure you haven’t change your code from last dated 2014 I have download?
        Thanks for your work!

        Like

      • Hi,

        have you see my project?
        i have see a strange things that i hope can help you, if i add a Debug.WriteLine(byteRead.Length);
        line all seems to work in debug but if i add some milliseconds of wait don’t work. naturally in release writeline not work 😦

        Like

      • Hey, I did run some tests… I did get the object closed exception after 600mb downloaded. I m thinking it might be related to the memory resources growing way out of proportion(I.e. The memory heap was around 650mb when it errored out). I will try to write it directly to storage next. As you said I had bunch of trace calls as well in the code.

        Like

      • Hi,
        i don’t think is memory problem, if i remove all write code and leave only

        while (true)
        {

        await stream.ReadAsync(newBuf, BUFFER_SIZE, InputStreamOptions.Partial);
        }

        i have the same problem and with memory profile the app don’t use more than 25mb of ram and appear don’t grow.

        Like

Leave a comment