Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 15th, 2012  |  syntax: None  |  size: 1.41 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. read an image (TIF image) from FTP Server
  2. //CREATE AN FTP REQUEST WITH THE DOMAIN AND CREDENTIALS
  3.                     System.Net.FtpWebRequest tmpReq =     (System.Net.FtpWebRequest)System.Net.FtpWebRequest.Create(filePath);
  4.                     tmpReq.Credentials = new System.Net.NetworkCredential(userName, password);
  5.                 //GET THE FTP RESPONSE
  6.                 using (System.Net.WebResponse tmpRes = tmpReq.GetResponse())
  7.                 {
  8.                     //GET THE STREAM TO READ THE RESPONSE FROM
  9.                     using (System.IO.Stream tmpStream = tmpRes.GetResponseStream())
  10.                     {
  11.                         //CREATE A TXT READER (COULD BE BINARY OR ANY OTHER TYPE YOU NEED)
  12.                         using (System.IO.TextReader tmpReader = new System.IO.StreamReader(tmpStream))
  13.                         {
  14.  
  15.                             //read and view image
  16.  
  17.  
  18.                         }
  19.                     }
  20.                 }
  21.             }
  22.        
  23. class Program
  24. {
  25.     static void Main()
  26.     {
  27.         var filePath = "ftp://example.com/foo.tif";
  28.         var request = WebRequest.Create(filePath);
  29.         request.Credentials = new NetworkCredential("user", "pass");
  30.         using (var response = request.GetResponse())
  31.         using (var stream = response.GetResponseStream())
  32.         using (var img = Image.FromStream(stream))
  33.         {
  34.             img.Save("foo.jpg", ImageFormat.Jpeg);
  35.         }
  36.     }
  37. }