【问题标题】:FtpWebRequest could not found in Portable Class Library在可移植类库中找不到 FtpWebRequest
【发布时间】:2013-07-26 07:03:10
【问题描述】:

我正在尝试在 ftp 网络服务器上上传文件。我在 windows phone 中找不到 FtpWebRequest 类,所以我正在尝试通过添加 Portable Class Library 的新项目。我添加了以下代码

 public void GetDataUsingDataContract(byte[] fileByte)
    {
        FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/test.htm");
        request.Method = WebRequestMethods.Ftp.UploadFile;

        // This example assumes the FTP site uses anonymous logon.
        request.Credentials = new NetworkCredential("uname", "pass");

        // Copy the contents of the file to the request stream.
       // StreamReader sourceStream = new StreamReader("testfile.txt");
        byte[] fileContents = fileByte;//Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
        //sourceStream.Close();
        request.ContentLength = fileContents.Length;

        Stream requestStream = request.GetRequestStream();
        requestStream.Write(fileContents, 0, fileContents.Length);
        requestStream.Close();

        FtpWebResponse response = (FtpWebResponse)request.GetResponse();

        Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);

        response.Close();
    }

但也有同样的问题,即我找不到 FtpWebResponse 类。可移植类库是否支持?

【问题讨论】:

    标签: windows-phone-7 windows-phone-8 portable-class-library ftpwebrequest


    【解决方案1】:

    我猜你已经有了答案,FTPWebRequest / FTPWebResponse 在 .NET 的可移植子集中不可用。

    此子集由您可以在所有框架(Silverlight、XBox、Windows Phone 7/8、.Net x.y 等)上找到的 API 组成

    如果您在本机框架(例如 Windows Phone)中找不到 api,您将无法在可移植库子集中找到它。

    如果你想在 windows phone 上使用 ftp,我猜你必须找到一个像 OpenNETCF FTP 这样为紧凑框架构建的第三方 api。

    https://ftp.codeplex.com/

    【讨论】:

      【解决方案2】:

      我不知道您是否考虑过Xamarin,但您正在寻找的实现可在System.Net.FtpWebRequest 获得。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-08-02
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多