我安装了“windows 10 pro”和全新安装的“visual studio community edition 2015”。
我做了一个新的项目控制台应用程序并将其命名为ftptest 然后从这里复制并粘贴代码:
https://msdn.microsoft.com/en-us/library/ms229716%28v=vs.110%29.aspx
using System;
using System.IO;
using System.Net;
namespace ftpcheck
{
public class Program
{
public void Main(string[] args)
{
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://www.contoso.com/");
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential("anonymous", "janeDoe@contoso.com");
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
Console.WriteLine(reader.ReadToEnd());
Console.WriteLine("Directory List Complete, status {0}", response.StatusDescription);
reader.Close();
response.Close();
}
}
}
尝试构建它只是为了看它是做什么的。
我得到了很多:
CS0246找不到类型或命名空间名称'FtpWebRequest'(您是否缺少using指令或程序集引用?)
CS0246找不到类型或命名空间名称“NetworkCredential”(您是否缺少using指令或程序集引用?)
如何添加缺少的参考?
答案 0 :(得分:0)
如果您查看msdn,您将看到必须添加的引用:
https://msdn.microsoft.com/en-us/library/system.net.ftpwebrequest(v=vs.110).aspx
Namespace: System.Net
Assembly: System (in System.dll)