我不知道下载的文件到底存放在那里的 请高手指教一下 谢谢下面的代码示例演示如何使用 WebClient 类从 FTP 服务器下载文件。
Uri uri = new Uri("ftp://172.21.0.66/新建 BMP 图像.bmp");
public static bool DisplayFileFromServer(Uri serverUri)
{
    // The serverUri parameter should start with the ftp:// scheme.
    if (serverUri.Scheme != Uri.UriSchemeFtp)
    {
        return false;
    }
    // Get the object used to communicate with the server.
    WebClient request = new WebClient();
    
    // This example assumes the FTP site uses anonymous logon.
    request.Credentials = new NetworkCredential ("anonymous","[email protected]");
    try 
    {
        byte [] newFileData = request.DownloadData (serverUri.ToString());
        string fileString = System.Text.Encoding.UTF8.GetString(newFileData);
        Console.WriteLine(fileString);
    }
    catch (WebException e)
    {
        Console.WriteLine(e.ToString());
    }
    return true;
}

解决方案 »

  1.   

    检查这个serverUri 的格式是不是  ftp:// // The serverUri parameter should start with the ftp:// scheme.
        if (serverUri.Scheme != Uri.UriSchemeFtp)
        {
            return false;
        }
      

  2.   

    你这个代码我看了,又不是下载文件的代码,你仔细看这三句:
    byte [] newFileData = request.DownloadData (serverUri.ToString());
    string fileString = System.Text.Encoding.UTF8.GetString(newFileData);
    Console.WriteLine(fileString);
    特别是最后这一句,这段代码实际上只是个读取远程文件的内容然后在控制台显示出来。
      

  3.   

    应该先new一个FileStream,然后往这个里面写你下载到的字节newFileData。
      

  4.   

    呵呵,其实很简单
    注意:byte [] newFileData = request.DownloadData (serverUri.ToString());
    换为:byte [] newFileData = request.DownloadFile (serverUri.ToString());
    再去试试吧