FtpWebRequest ftpRequest = (FtpWebRequest)FtpWebRequest.Create(new Uri("file location")); //set the method to Upload, since we're uploading a file ftpRequest.Method = WebRequestMethods.Ftp.UploadFile; //pass in our login credentials ftpRequest.Credentials = new NetworkCredential("username", "password"); //don't use passive mode ftpRequest.UsePassive = true; //unless we're uploading a file like an image //we need to set this to false as we're not uploading //binary data ftpRequest.UseBinary = true; //set KeepAlive to false ftpRequest.KeepAlive = false; //now create a new FileStream, then open the file we're uploading //this allows us to get the size of the file for our buffer FileStream stream = File.OpenRead("local file path"); //create a byte[] array buffer the size of the file //we're uploading byte[] buffer = new byte[stream.Length]; //read in our file into the FileStream stream.Read(buffer, 0, buffer.Length); //close the FileStream stream.Close(); //create a new stream, this will be used to write to the //FTP server Stream requestStream1 = ftpRequest.GetRequestStream(); //write the data to the FTP server requestStream.Write(buffer, 0, buffer.Length); //close the stream requestStream.Close();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)