我想知道是否可以使用FtpWebRequest
爲我的FTP客戶端輸出日誌。使用FtpWebRequest輸出日誌
事情是這樣的:
[R] USER xxx
[R] 331 Please specify the password.
[R] PASS (hidden)
[R] 230 Login successful.
[R] SYST
[R] 215 UNIX Type: L8
[R] FEAT
[R] 211-Features:
[R] EPRT
[R] EPSV
[R] MDTM
[R] PASV
[R] REST STREAM
[R] SIZE
[R] TVFS
[R] 211 End
[R] PWD
[R] 257 "/"
[R] CWD/
[R] 250 Directory successfully changed.
[R] PWD
[R] 257 "/"
[R] TYPE A
[R] 200 Switching to ASCII mode.
[R] PASV
[R] 227 Entering Passive Mode (10,232,201,81,141,175)
[R] Opening data connection IP: 10.232.201.81 PORT: 36271
[R] LIST -al
[R] 150 Here comes the directory listing.
[R] 226 Directory send OK.
這個輸出例如連接時...
我當前的代碼僅執行以下操作:參考
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create(string.Format("ftp://{0}", addrEndPoint));
request.Method = WebRequestMethods.Ftp.ListDirectoryDetails;
request.Credentials = new NetworkCredential(_currentConnection.Username, _currentConnection.Password);
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
Stream responseStream = response.GetResponseStream();
StreamReader readStream = new StreamReader(responseStream, System.Text.Encoding.UTF8);
if (readStream != null)
{
Console.WriteLine(readStream.ReadToEnd());
}
tracemode和maxdatasize屬性是不允許的...... – kaycee 2012-03-12 14:20:13
它說,但沒關係,它應該正常工作。 – svick 2012-03-12 15:39:02
嗨,解決方案看起來不錯,並回答我的期望,但它有可能得到這個信息,而不是寫入文件? – kaycee 2012-03-13 14:48:31