Social Icons

Saturday, March 24, 2012

Uploading Image or file on FTP programatically using Asp.net File Uploader

Dear friends following is the programmatic solution which can used to upload any image on FTP using FTP credentials....

 public void ftpfile(string ftpfilepath)
 {
     string ftphost = "Domain";
     //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("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();
}

Hope this will work for you.....

1 comment:

 

Sample text

Sample Text