Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. string FTP_HOST = "Host IP";
  2. string FTP_USER = "User";
  3. string FTP_PASS = "Passw";
  4. string FTP_UPLOADBASEPATH = "Test";
  5. string filemanage = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), fileToSent);
  6. string source = Path.GetFileName(fileToSent);
  7. var ftp = (FtpWebRequest)WebRequest.Create(FTP_HOST + "/" + FTP_UPLOADBASEPATH + "/" + source);
  8. ftp.Credentials = new NetworkCredential(FTP_USER, FTP_PASS);
  9. ftp.KeepAlive = true;
  10. ftp.UseBinary = true;
  11. ftp.UsePassive = true;
  12. ftp.Method = WebRequestMethods.Ftp.UploadFile;
  13. FileStream fs = File.OpenRead(filemanage);
  14. byte[] buffer = new byte[fs.Length];
  15. fs.Read(buffer, 0, buffer.Length);
  16. fs.Close();
  17. Stream ftpstream = ftp.GetRequestStream();
  18. ftpstream.Write(buffer, 0, buffer.Length);
  19. ftpstream.Close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement