Browsing all articles tagged with FTP Upload
Aug
4

How to upload a file to ftp server with FileUpload control

private bool UploadToFTP(string ftpfilepath,HttpPostedFile fileToUpload)
{
try
{
string ftphost = "ftpaddress";
string ftpfullpath = "ftp://" + ftphost + ftpfilepath;
Stream streamObj = fileToUpload.InputStream;
Byte[] buffer = new Byte[fileToUpload.ContentLength];
streamObj.Read(buffer, 0, buffer.Length);
streamObj.Close();
streamObj = null;
FtpWebRequest requestObj = FtpWebRequest.Create(ftpfullpath) as FtpWebRequest;
requestObj.Method = WebRequestMethods.Ftp.UploadFile;
requestObj.Credentials = new NetworkCredential("username", "password");
Stream requestStream = requestObj.GetRequestStream();
requestStream.Write(buffer, 0, buffer.Length);
requestStream.Flush();
requestStream.Close();
requestObj = null;
return true;
}
catch
{
return false;
}
}
Follow us on Twitter! Follow us on Twitter!
FoxSparrow Tweets

Categories