public void ListFilesOnRemoteServer_RemoteLs_FailureResult() { var mainRequest = new FtpHandler(); mainRequest.url = "ftp://13.59.40.218/"; mainRequest.userName = "******"; mainRequest.securePwd = new NetworkCredential("", "Kamono12345").SecurePassword; var remoteLs = new RemoteLS(); //Act var response = remoteLs.ListRemote(mainRequest); //Assert Assert.IsFalse(response); }
static void Main(string[] args) { FtpHandler mainHandler = new FtpHandler(); RemoteLS listRemote = new RemoteLS(); RemoteMkDir mkDirRemote = new RemoteMkDir(); Upload upload = new Upload(); Download download = new Download(); Rename rename = new Rename(); Delete delete = new Delete(); mainHandler.LogOnInitial(); try { bool loop = true; while (loop) { Console.WriteLine("\nEnter a command:\nls = List Directory Details\nupload = UpLoad File\nupload-m = Upload Multiple files\ndownload = DownLoad File\ndelete = Delete a File\nrr = Rename a Remote File\nmkdir = Make a Remote Directory\nsave = Save currenly connected server \nd = Disconnect\n"); timer = new System.Timers.Timer(); timer.Interval = 10000; timer.Elapsed += OnTimedEvent; timer.AutoReset = true; timer.Enabled = true; string command = Console.ReadLine(); timer.Enabled = false; switch (command.ToLower()) { case "upload": Console.WriteLine("Enter the filename to put on the ftp.\n"); string upFile = Console.ReadLine(); upload.UploadToRemote(mainHandler, upFile); break; case "upload-m": Console.WriteLine("Enter the filename to put on the ftp seperated by \";\"'s.\n"); string upFiles = Console.ReadLine(); upload.UploadMultipleToRemote(mainHandler, upFiles); break; case "download": Console.WriteLine("Enter filename to take from the ftp.\n"); string downFile = Console.ReadLine(); download.DownloadFromRemote(mainHandler, downFile); break; case "delete": Console.WriteLine("Enter filename to DELETE from the ftp.\n"); string deleteFile = Console.ReadLine(); delete.DeleteRemoteFile(mainHandler, deleteFile); break; case "ls": listRemote.ListRemote(mainHandler); break; case "rr": Console.WriteLine("Enter filename to Rename from the ftp.\n"); string currnetFile = Console.ReadLine(); Console.WriteLine("Enter the new name.\n"); string newFileName = Console.ReadLine(); rename.RenameRemoteFile(mainHandler, currnetFile, newFileName); break; case "d": loop = false; break; case "mkdir": Console.WriteLine("Enter directory name. \n"); string dir = Console.ReadLine(); mkDirRemote.MkDirRemote(mainHandler, dir); break; case "save": mainHandler.SaveInfo(); break; default: Console.WriteLine("Wrong Command.\n"); break; } command = string.Empty; } Console.WriteLine("Press enter to disconnect"); Console.ReadLine(); mainHandler.LogOff(); } catch (Exception ex) { Console.WriteLine(ex); File.WriteAllText("log.txt", ex.ToString()); } }
private bool LogOnUnsaved() { try { bool loggedOn = false; RemoteLS listRemote = new RemoteLS(); while (!loggedOn) { //Prompt for FTP URL, and add into FtpWebRequest. //Keep in mind that this needs to be a full URL, which should look something like this: ftp://HostName.com/ //This also initializes FtpWebRequest, which is kinda major. Maybe we should find a way to move this? //Maybe mainHandler constructor? Console.Write("Enter an FTP server URL: "); timer = new System.Timers.Timer(); timer.Interval = 10000; timer.Elapsed += OnTimedEvent; timer.AutoReset = true; timer.Enabled = true; url = Console.ReadLine(); timer.Enabled = false; //Allows a user to log on to an FTP server with username and password. //Prompts user for username, domain, and password //Username Console.Write("Enter username: "******"Enter password: "******"*"); } // Exit if Enter key is pressed. } while (key.Key != ConsoleKey.Enter); Console.WriteLine(); mainRequest = (FtpWebRequest)WebRequest.Create(url); //HUGE: with EnableSsl = false, your username and password will be transmitted over the network in cleartext. //Please don't transmit your username and password over the network in cleartext :) mainRequest.EnableSsl = true; //Allows mainRequest to make multiple requests. Otherwise, connection will close after one request. mainRequest.KeepAlive = true; //maybe we could prompt for this? I'm not sure if it matters. Can be tacked on to the end of a NetworkCredential constructor. /* * //Domain * Console.Write("Enter Domain: "); * string domain = Console.ReadLine(); */ //Now, we feed all of these into a NetworkCredentials class, and feed that into our FtpWebRequest mainRequest.Credentials = new NetworkCredential(userName, securePwd); //Other parameters that are important to have mainRequest.KeepAlive = true; mainRequest.UseBinary = true; mainRequest.UsePassive = true; loggedOn = listRemote.ListRemote(this); if (loggedOn) { Console.WriteLine("logOn successfull\n"); } else { Console.WriteLine("Failed to log in\n"); } } return(true); } catch (Exception OhNo) { Console.WriteLine(OhNo.Message.ToString()); return(false); } }