ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
Article:
  Building FTP Services Using .NET 2.0
Subject:   Building FTP Services
Date:   2009-11-18 06:54:47
From:   tapsa_gbg
Response to: Building FTP Services

string username = "*****";
string password = "*****";
//string domain = "****";


string filename = @"C:\test\HelloWorld.txt";
string address = "ftp://****";


try
{
FtpWebRequest ftpReq = (FtpWebRequest)WebRequest.Create(address);
ftpReq.Method = WebRequestMethods.Ftp.UploadFile;
ftpReq.Credentials = new NetworkCredential(username, password);
StreamReader stream = new StreamReader(filename);
byte[] b = System.Text.Encoding.UTF8.GetBytes(stream.ReadToEnd());
stream.Close();


ftpReq.ContentLength = b.Length;
Stream s = ftpReq.GetRequestStream();
s.Write(b, 0, b.Length);
s.Close();


FtpWebResponse ftpResp = (FtpWebResponse)ftpReq.GetResponse();
Console.WriteLine(ftpResp.StatusDescription);
}
catch (Exception ex)
{
Console.WriteLine(String.Format("ftpwebrequest: {0}, {1}", DateTime.Now.ToString(), ex.Message));
}
Console.ReadLine();