In this web programming tutorial we will learn that how we can Upload Image or file on FTP in Asp.net File Uploader using c#.
copy the below code in your .cs file.
public void ftpfile(string ftpfilepath)
{
string ftphost = "your domain name ";
//here correct hostname or IP of the ftp server to be given
string ftpfullpath = "ftp://" + ftphost + ftpfilepath;
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
ftp.Credentials = new NetworkCredential("your Domain", "Password");
//userid and password for the ftp server to given
ftp.KeepAlive = true;
ftp.UseBinary = true;
ftp.Method = WebRequestMethods.Ftp.UploadFile;
// Resize Image is function to resize the image
System.Drawing.Image img1 =
ResizeImage(FileUpload1.PostedFile.InputStream, 84, 118);
// Convert the image into bytes Array;
byte[] buffer = ImageToByte(img1);
// Send the image file in form of bytes
Stream ftpstream = ftp.GetRequestStream();
ftpstream.Write(buffer, 0, buffer.Length);
ftpstream.Close();
}
Tags:
asp.net