Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.IO.Compression;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Threading.Tasks;
- using System.Configuration;
- namespace SEND_Plovdiv
- {
- public class WebRequestGetExample
- {
- public static void Main()
- {
- string[] lineOfContents = File.ReadAllLines(@"C:\Msend.txt");
- string username = "";
- string password = "";
- foreach (var line in lineOfContents)
- {
- string[] tokens = line.Split(',');
- string user = tokens[0];
- string pass = tokens[1];
- username = user;
- password = pass;
- }
- string pathFile = @"C:MTelegrami";
- string zipPath = @"C:MPlovdiv.zip";
- if (File.Exists(zipPath))
- {
- File.Delete(zipPath);
- }
- ZipFile.CreateFromDirectory(pathFile, zipPath, CompressionLevel.Fastest, false);
- // Get the object used to communicate with the server.
- FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp://199.199.199.199/Plovdiv.zip");
- request.Method = WebRequestMethods.Ftp.UploadFile;
- // This example assumes the FTP site uses anonymous logon.
- request.Credentials = new NetworkCredential(username, password);
- // Copy the contents of the file to the request stream.
- StreamReader sourceStream = new StreamReader(@"C:MPlovdiv.zip");
- byte[] fileContents = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd());
- sourceStream.Close();
- request.ContentLength = fileContents.Length;
- Stream requestStream = request.GetRequestStream();
- requestStream.Write(fileContents, 0, fileContents.Length);
- requestStream.Close();
- FtpWebResponse response = (FtpWebResponse)request.GetResponse();
- Console.WriteLine("Upload File Complete, status {0}", response.StatusDescription);
- Console.ReadKey();
- response.Close();
- }
- }
- }
- StreamReader sourceStream = new StreamReader(@"C:MPlovdiv.zip");
Add Comment
Please, Sign In to add comment