解决方法
使用
FtpWebRequest类或普通的
WebClient类.
FTP进入帐户并检索文件:
WebClient request = new WebClient(); request.Credentials = new NetworkCredential("anonymous","janeDoe@contoso.com"); try { // serverUri here uses the FTP scheme ("ftp://"). byte[] newFileData = request.DownloadData(serverUri.ToString()); string fileString = Encoding.UTF8.GetString(newFileData); } catch (WebException ex) { // Detect and handle login failures etc here }
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(serverUri); request.Method = WebRequestMethods.Ftp.DeleteFile; FtpWebResponse response = (FtpWebResponse)request.GetResponse(); Console.WriteLine("Delete status: {0}",response.StatusDescription); response.Close();
(代码示例来自MSDN.)