I remove some code that can extract files either from the local file system, or from http or ftp. To disable it, I created a simple method that uses the HTTPListener class from BCL to start a one-time web server in another thread, it just serves the byte array that I send and then disconnects. (See Code for this below).
I am just wondering if there is any easy way to do the same for ftp? In .NET there is no such thing as an FTPListener class (as far as I know). I don’t know much about FTP, but as far as I know, there is a control channel and a data channel, so I can imagine that it will be a little more complicated than the http example below. So, any ideas without writing this from scratch using sockets? Any classes I could use?
public static void Serve(int port, int statusCode, byte[] responseBody,
Dictionary<string,string> headers)
{
new Thread(delegate()
{
var listener = new HttpListener();
listener.Prefixes.Add(string.Format("http://localhost:{0}/", port));
listener.Start();
var context = listener.GetContext();
context.Response.StatusCode = statusCode;
context.Response.ContentLength64 = responseBody.Length;
if (headers != null)
{
foreach (string header in headers.Keys)
{
context.Response.AddHeader(header, headers[header]);
}
}
context.Response.OutputStream.Write(responseBody, 0, responseBody.Length);
context.Response.OutputStream.Close();
listener.Stop();
}).Start();
}