locked
having problem to translate from WinForm to Windows-CE C# program - FTP transfer RRS feed

  • Question

  • having problem to translate from WinForm to Windows-CE C# program - FTP transfer
     
    i have this code for transfer from Local computer to FTP server
     
    its work excellent on WinForm, i must have this on Windows-CE and it dosnt work
     
    the code:
     
    string MyFile = @"d:\PC.sdf";
     
    string url = "ftp://127.0.0.1/PC.sdf";
    FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(url);
     
    request.Method = WebRequestMethods.Ftp.UploadFile;
    //request.Credentials = new NetworkCredential("user name", "password");
    request.UsePassive = true;
    request.UseBinary = true;
    request.KeepAlive = false;
     
    //byte[] buffer = File.ReadAllBytes(MyFile);
     
    using (Stream reqStream = request.GetRequestStream())
    {
    int count = 0;
    byte[] buffer = new byte[100];
    using (FileStream file = new FileStream(MyFile, FileMode.Open))
    {
    while ((count = file.Read(buffer, 0, 100)) > 0)
    {
    reqStream.Write(buffer, 0, count);
    }
    }
     
    }
    thanks in advance

    Friday, August 12, 2011 7:28 AM

Answers

  • Hello,

     

    Did you use .NET Compact Framework? I find the FtpWebRequest Class is not supported by .NET Compact Framework, so that your codes cannot work on Windows CE.

     

    However, you can use the native FTP API, please follow the native sample codes in the MSDN document.

    Enumerating Directories.

     

    Meanwhile, you can follow this blog to use C# and p/invoke to call the APIs in WinInet.dll. But you need to change some codes in this, because this project is not based on Windows Mobile.

    C# FTP client, based on the WinInet.dll API

     

    I hope my suggestions can help you to solve this problem.

     

    Best regards,

    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Proposed as answer by Jesse Jiang Wednesday, August 17, 2011 7:43 AM
    • Marked as answer by Jesse Jiang Friday, August 19, 2011 8:13 AM
    Monday, August 15, 2011 7:49 AM