using System; using System.IO; using System.Net; using System.Text; namespace FileTransfer { class Program { public static void Main() { string ftppath = "ftp://149.223.26.33//D://Developers/muralim/TRW.HRM.Headcount_LMSFeed/Log/"; FtpWebRequest request = (FtpWebRequest)WebRequest.Create(ftppath + @"/" + "employeedetails1.txt");//this is the text file i need to copy to the server. request.Method = WebRequestMethods.Ftp.UploadFile; request.Credentials = new NetworkCredential("rajeshb", "Satyam*03"); request.Timeout = 1000000000; StreamReader sourceStream = new StreamReader(@"C:\Documents and Settings\aj99823\Desktop\project\employeedetails1.txt");//this is the current path of the file in the local machine byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd()); sourceStream.Close(); request.ContentLength = fileContents.Length; request.Proxy = null; Stream requestStream = request.GetRequestStream(); requestStream.Write(fileContents, 0, fileContents.Length); requestStream.Close(); FtpWebResponse response = (FtpWebResponse)request.GetResponse(); Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription); response.Close(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)