csaki

FTP save file function

Aug 10th, 2013
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.09 KB | None | 0 0
  1. // FTP-re mentés:
  2.  
  3. public static void SaveFile(string Content, string Filename, string FTPServer, string Username, string Password)
  4.         {
  5.             try
  6.             {
  7.                 Uri requestUri = new Uri(Path.Combine(FTPServer, Filename));
  8.                 FtpWebRequest request = (FtpWebRequest)WebRequest.Create(requestUri);
  9.                 request.Credentials = new NetworkCredential(Username, Password);
  10.                 request.KeepAlive = false;
  11.                 request.Method = "STOR";
  12.                 request.UseBinary = true;
  13.                 request.ContentLength = Content.Length;
  14.                 request.Proxy = null;
  15.                 using (Stream stream = request.GetRequestStream())
  16.                 {
  17.                     byte[] bytes = new UnicodeEncoding().GetBytes(Content);
  18.                     stream.Write(bytes, 0, bytes.Length);
  19.                 }
  20.                 request.GetResponse();
  21.             }
  22.             catch (Exception ex)
  23.             {
  24.                 MessageBox.Show("Hiba történt a fájl mentése során!\n\n" + ex.Message);
  25.             }
  26.         }
Advertisement
Add Comment
Please, Sign In to add comment