Browsing all articles tagged with FTP Upload
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;
}
}
{
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;
}
}
Categories
- Dot Net (12)
- .Net Framework (1)
- Ajax (1)
- ASP.NET (6)
- C#.NET (3)
- Code Snippets (3)
- WCF (1)
- SQL Server (3)
- Tutorials (1)
- Video (1)




