Advertisement
Pi0trek

FTPmain

Aug 16th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ClientFTP
  8. {
  9.     class Program
  10.     {
  11.         static FTP ftp;
  12.  
  13.         // sftp://username:password@domain:port
  14.         static void Main(string[] args)
  15.         {
  16.             string port = "21", hostname = "", username = "", password = "";
  17.             int intPort;
  18.             /*
  19.             Console.WriteLine("Podaj port:");
  20.             port = Console.ReadLine();
  21.             Console.WriteLine("Podaj domene:");
  22.             domain = Console.ReadLine();
  23.             Console.WriteLine("Podaj nazwe uzytkownika:");
  24.             username = Console.ReadLine();
  25.             Console.WriteLine("Podaj haslo:");
  26.             password = Console.ReadLine();
  27.             */
  28.  
  29.             ftp = new FTP(username, password, hostname, int.TryParse(port, out intPort) ? intPort : 21);
  30.             mainLoop();
  31.         }
  32.  
  33.  
  34.         static void mainLoop()
  35.         {
  36.             Console.Clear();
  37.  
  38.             Console.WriteLine("Polaczono z " + ftp.hostname + "!");
  39.             Console.WriteLine("Zawartosc katalogu " + ftp.currentDirectoryAbsolute + " :");
  40.  
  41.             Console.WriteLine(ftp.getDirectoryContents());
  42.  
  43.             bool flagExit = false;
  44.             while(!flagExit)
  45.             {
  46.                 Console.WriteLine("Dostepne opcje:");
  47.                 Console.WriteLine("1: wyswietl pelna sciezke biezacego katalogu");
  48.                 Console.WriteLine("2: wyswietl zawartosc biezacego katalogu");
  49.                 Console.WriteLine("3: wyswietl drzewo katalogow i plikow zaczynajac od biezacego katalogu");
  50.                 Console.WriteLine("4: wyswietl drzewo katalogow i plikow zaczynajac od roota");
  51.                 Console.WriteLine("5: zmien katalog");
  52.                 Console.WriteLine("0: wyjscie");
  53.  
  54.                 int choice = -1;
  55.                 if (!int.TryParse(Console.ReadLine(), out choice))
  56.                     choice = -1;
  57.  
  58.                 Console.Clear();
  59.  
  60.                 switch (choice)
  61.                 {
  62.                     case 0:
  63.                         flagExit = true;
  64.                         break;
  65.                     case 1:
  66.                         Console.WriteLine("Biezacy katalog: " + ftp.currentDirectoryAbsolute);
  67.                         break;
  68.                     case 2:
  69.                         Console.WriteLine("Zawartosc katalogu: " + ftp.currentDirectoryAbsolute + " :\n");
  70.                         Console.WriteLine(ftp.getDirectoryContents());
  71.                         break;
  72.                     case 3:
  73.                         Console.WriteLine("Drzewo katalogow: " + ftp.currentDirectoryAbsolute + " :\n");
  74.                         Console.WriteLine(ftp.printDirectoryTree(ftp.currentDirectory));
  75.                         break;
  76.                     case 4:
  77.                         Console.WriteLine("Drzewo katalogow: \n");
  78.                         Console.WriteLine(ftp.printDirectoryTree("/"));
  79.                         break;
  80.                     case 5:
  81.                         Console.WriteLine("Podaj sciezke do nowego katalogu: ");
  82.                         string dir = Console.ReadLine();
  83.                         ftp.changeDirectory(dir);
  84.                         Console.WriteLine("Biezacy katalog: " + ftp.currentDirectoryAbsolute + "\n");
  85.                         break;
  86.                     case -1:
  87.                         Console.WriteLine("Niepoprawna opcja!");
  88.                         break;
  89.                 }
  90.             }
  91.         }
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement