Skip to content

Instantly share code, notes, and snippets.

@DominicFinn
Created November 28, 2011 17:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DominicFinn/1401094 to your computer and use it in GitHub Desktop.
Save DominicFinn/1401094 to your computer and use it in GitHub Desktop.
Ftp Upload Example. Quick and dirty.
public class FtpUpload
{
public void Ftpfile()
{
string ftphost = "ftp.mmfn.co.uk/";
WebRequest request = WebRequest.Create("ftp://" + ftphost + "public_html/test.html");
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("username", @"password");
StreamReader sourceStream = new StreamReader("test.html");
byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
sourceStream.Close();
request.ContentLength = fileContents.Length;
Stream requestStream = request.GetRequestStream();
requestStream.Write(fileContents, 0, fileContents.Length);
requestStream.Close();
using (var resp = (FtpWebResponse)request.GetResponse())
{
Console.WriteLine("Upload File Complete, status {0}", resp.StatusDescription);
Console.WriteLine(resp.StatusCode);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment