I wonder if it's possible to have output log for my FTP client using FtpWebRequest
.
Something like this:
[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.
This output for example is when connecting...
My current code only does the following:
// 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());
}
You can do this using Network Tracing. To set it up, create (or modify, if you already have one)
App.config
file, so that it looks like this (if you already have the file, you will need to add the settings to it):If you do this, your application will create a
network.log
file, that might look something like this:It's quite verbose, but it does contain the information you need. If you want to modify how is the log file written, you can implement your own
TraceListener
and use that in the config file instead ofTextWriterTraceListener
.check these following links for reference. if you have IIS 7 then it is possible to implement your own functionality.
implementing IFtpLogProvider interface's Log method
Ref:
IIS FTP 7.5 Extensibility (IFtpLogProvider and logging FTP failures to the event log)
Problem writing to a file (C#)