Created
November 28, 2011 17:00
-
-
Save DominicFinn/1401094 to your computer and use it in GitHub Desktop.
Ftp Upload Example. Quick and dirty.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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