Guest User

Untitled

a guest
Apr 9th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.73 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. using System.Net;
  9. using System.IO;
  10. using System.Security.Cryptography;
  11.  
  12. namespace Uploader
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         //static public string filename = "";
  17.         public Stream reqStream;
  18.         public Form1()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.  
  23.         private void Form1_Load(object sender, EventArgs e)
  24.         {
  25.  
  26.         }
  27.  
  28.         private void timer1_Tick(object sender, EventArgs e)
  29.         {
  30.            // try
  31.            // {
  32.            //     Application.DoEvents();
  33.              //   MessageBox.Show(reqStream.Position.ToString());
  34.                 //progressBar1.Value = (Int32)
  35.                 //    ((reqStream.Position * 100) / reqStream.Length);
  36.            // }
  37.            // catch (Exception se) { }
  38.         }
  39.  
  40.         protected string MD5(string fileName)
  41.         {
  42.             if (!File.Exists(fileName)) return "CHUJ";
  43.             FileStream file = new FileStream(fileName, FileMode.Open);
  44.             MD5 md5 = new MD5CryptoServiceProvider();
  45.             byte[] retVal = md5.ComputeHash(file);
  46.             file.Close();
  47.  
  48.             StringBuilder sb = new StringBuilder();
  49.             for (int i = 0; i < retVal.Length; i++)
  50.             {
  51.                 sb.Append(retVal[i].ToString("x2"));
  52.             }
  53.             return sb.ToString();
  54.         }
  55.  
  56.         public void upload()
  57.         {
  58.             string user = File.ReadAllText("user.txt");
  59.             string password = File.ReadAllText("password.txt");
  60.             string destination = File.ReadAllText("destination.txt");
  61.             string[] get = File.ReadAllLines("links.txt");
  62.  
  63.  
  64.             System.Net.WebClient c = new System.Net.WebClient();
  65.  
  66.             foreach (string link in get)
  67.             {
  68.                 //MessageBox.Show(link.LastIndexOf("/").ToString());
  69.                 string linkfile;
  70.                 if (link.IndexOf("download.php?") != -1) linkfile = "gmer.exe"; else
  71.                 linkfile = link.Substring(link.LastIndexOf("/")+1, link.Length - link.LastIndexOf("/")-1);
  72.                 //MessageBox.Show("links\\" + linkfile + ".down");
  73.                 c.DownloadFile(link, "links\\" + linkfile + ".down");
  74.                 if(MD5("links\\" + linkfile + ".down")
  75.                     != MD5("links\\" + linkfile)){
  76.                         File.Delete("links\\" + linkfile);
  77.                         File.Move(
  78.                             "links\\" + linkfile + ".down",
  79.                             "links\\" + linkfile
  80.                         );
  81.                         FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create(new Uri(destination + linkfile));
  82.                         request.Method = WebRequestMethods.Ftp.UploadFile;
  83.                         request.Credentials = new NetworkCredential(user, password);
  84.                         request.UsePassive = true;
  85.                         request.UseBinary = true;
  86.                         request.KeepAlive = false;
  87.                         FileStream stream = File.OpenRead("links\\" + linkfile);
  88.                         byte[] buffer = new byte[stream.Length];
  89.  
  90.                         stream.Read(buffer, 0, buffer.Length);
  91.                         stream.Close();
  92.                         //label1.Text = linkfile;
  93.                         reqStream = request.GetRequestStream();
  94.                         for (int i = 0; i <= buffer.Length / 100; i++)
  95.                         {
  96.                             if ((i * 100) + 100 <= buffer.Length)
  97.                                 reqStream.Write(buffer, i * 100, 100);
  98.                             else reqStream.Write(buffer, i * 100, buffer.Length - (i * 100));
  99.                             //progressBar1.Value = ((i * 10000) / buffer.Length);
  100.                         }
  101.                         reqStream.Close();
  102.                 }
  103.             }
  104.  
  105.            // progressBar1.Value = 100;
  106.             MessageBox.Show("Done");
  107.             Application.ExitThread();
  108.             Application.Exit();
  109.         }
  110.  
  111.         private void Form1_Shown(object sender, EventArgs e)
  112.         {
  113.             Application.DoEvents();
  114.             //timer1.Enabled = true;
  115.             System.Threading.ThreadStart parameter = new System.Threading.ThreadStart(upload);
  116.             System.Threading.Thread lol = new System.Threading.Thread(parameter);
  117.             lol.Start();
  118.  
  119.         }
  120.  
  121.         private void Form1_FormClosing(object sender, FormClosingEventArgs e)
  122.         {
  123.             Application.Exit();
  124.         }
  125.  
  126.         private void Form1_ResizeBegin(object sender, EventArgs e)
  127.         {
  128.  
  129.         }
  130.     }
  131. }
Add Comment
Please, Sign In to add comment