SHARE
TWEET

Untitled

a guest Aug 26th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private static bool uploadtoftp(string localfile, String filename)
  2.         {
  3.             try
  4.             {
  5.                 Console.WriteLine("Uploading file to :" + FTPHost + FTPResultDirectory + filename);
  6.                 FtpWebRequest request = (FtpWebRequest)WebRequest.Create(FTPHost + FTPResultDirectory + filename);
  7.                 request.Method = WebRequestMethods.Ftp.UploadFile;
  8.                 request.UseBinary = true;
  9.                 request.UsePassive = true;
  10.                 request.KeepAlive = true;
  11.                 request.Credentials = new NetworkCredential(FTPUsername, FTPPassword);
  12.  
  13.  
  14.                 using (FileStream fs = File.OpenRead(@localfile))
  15.                 {
  16.                     byte[] buffer = new byte[fs.Length];
  17.                     fs.Read(buffer, 0, buffer.Length);
  18.                     fs.Close();
  19.                     Stream requestStream = request.GetRequestStream();
  20.                     requestStream.Write(buffer, 0, buffer.Length);
  21.                     requestStream.Flush();
  22.                     requestStream.Close();
  23.                     FtpWebResponse response = (FtpWebResponse)request.GetResponse();
  24.                     Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
  25.                     response.Close();
  26.                     Console.WriteLine("Success Upload File to FTP");
  27.                 }
  28.                 return true;
  29.             }
  30.             catch (Exception e)
  31.             {
  32.                 Console.WriteLine("Failed Upload File to FTP");
  33.                 Console.WriteLine(e);
  34.                 return false;
  35.             }
  36.  
  37.         }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top