Guest User

Untitled

a guest
Feb 6th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.27 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.IO.Compression;
  5. using System.Linq;
  6. using System.Net;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Configuration;
  10.  
  11.  
  12. namespace SEND_Plovdiv
  13. {
  14.  
  15. public class WebRequestGetExample
  16. {
  17.  
  18. public static void Main()
  19. {
  20. string[] lineOfContents = File.ReadAllLines(@"C:\Msend.txt");
  21.  
  22. string username = "";
  23. string password = "";
  24. foreach (var line in lineOfContents)
  25. {
  26. string[] tokens = line.Split(',');
  27. string user = tokens[0];
  28. string pass = tokens[1];
  29.  
  30. username = user;
  31. password = pass;
  32. }
  33.  
  34. string pathFile = @"C:MTelegrami";
  35. string zipPath = @"C:MPlovdiv.zip";
  36.  
  37. if (File.Exists(zipPath))
  38. {
  39. File.Delete(zipPath);
  40. }
  41.  
  42. ZipFile.CreateFromDirectory(pathFile, zipPath, CompressionLevel.Fastest, false);
  43.  
  44.  
  45. // Get the object used to communicate with the server.
  46. FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://199.199.199.199/Plovdiv.zip");
  47. request.Method = WebRequestMethods.Ftp.UploadFile;
  48.  
  49. // This example assumes the FTP site uses anonymous logon.
  50. request.Credentials = new NetworkCredential(username, password);
  51.  
  52. // Copy the contents of the file to the request stream.
  53. StreamReader sourceStream = new StreamReader(@"C:MPlovdiv.zip");
  54. byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
  55.  
  56. sourceStream.Close();
  57.  
  58. request.ContentLength = fileContents.Length;
  59.  
  60. Stream requestStream = request.GetRequestStream();
  61. requestStream.Write(fileContents, 0, fileContents.Length);
  62. requestStream.Close();
  63.  
  64. FtpWebResponse response = (FtpWebResponse)request.GetResponse();
  65.  
  66. Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
  67. Console.ReadKey();
  68.  
  69. response.Close();
  70.  
  71.  
  72. }
  73. }
  74. }
  75.  
  76. StreamReader sourceStream = new StreamReader(@"C:MPlovdiv.zip");
Add Comment
Please, Sign In to add comment