Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.02 KB | None | 0 0
  1. using System;
  2. using System.Net;
  3. using System.IO;
  4.  
  5. namespace CMD_Tchat
  6. {
  7.     class Program
  8.     {
  9.         string date;
  10.         string filePath;
  11.  
  12.         static void Main(string[] args)
  13.         {
  14.             Program program = new Program();
  15.             program.date = (DateTime.Now.Day + "." + DateTime.Now.Month + "." + DateTime.Now.Year);
  16.  
  17.             try
  18.             {
  19.                 if (!File.Exists(@"c:\programdata\cmd_tchat\" + program.date + ".txt"))
  20.                 {
  21.                     File.Create(@"c:\programdata\cmd_tchat\" + program.date + ".txt");
  22.                     return;
  23.                 } else
  24.                 {
  25.                     program.filePath = (@"c:\programdata\cmd_tchat\" + program.date + ".txt");
  26.                 }
  27.             } catch (DirectoryNotFoundException)
  28.             {
  29.                 Directory.CreateDirectory(@"c:\programdata\cmd_tchat");
  30.                 return;
  31.             }
  32.  
  33.             string inputFilePath = @"D:\Vrac\lol.txt";
  34.             string ftpHost = "127.0.0.1/";
  35.             string ftpFilePath = (program.date + ".txt");
  36.  
  37.             string ftpFullPath = "ftp://" + ftpHost + ftpFilePath;
  38.  
  39.             using (WebClient request = new WebClient())
  40.             {
  41.                 request.Credentials = new NetworkCredential("spylx", "");
  42.  
  43.                 byte[] fileData;
  44.                 try
  45.                 {
  46.                     fileData = request.DownloadData(ftpFullPath);
  47.                 } catch
  48.                 {
  49.                     Console.WriteLine(ftpFullPath);
  50.                     Console.WriteLine(program.filePath);
  51.                     request.UploadFile(ftpFullPath, program.filePath);
  52.                     return;
  53.                 }
  54.  
  55.                 using (FileStream file = File.Create(inputFilePath))
  56.                 {
  57.                     file.Write(fileData, 0, fileData.Length);
  58.                     file.Close();
  59.                 }
  60.                 Console.WriteLine("Download Complete");
  61.                
  62.             }
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement