public void DrawListing() { DFtpResult result = null; DFtpAction action = null; if (Client.state == ClientState.VIEWING_LOCAL) { ConsoleUI.WriteLine("(Show hidden = " + Client.view_hidden + ") " + "Listing for: " + Client.localDirectory, Color.Gold); action = new GetListingLocalAction(Client.localDirectory, Client.view_hidden); } else if (Client.state == ClientState.VIEWING_REMOTE) { ConsoleUI.WriteLine("(Show hidden = " + Client.view_hidden + ") " + "Listing for: " + Client.remoteDirectory, Color.Gold); action = new GetListingRemoteAction(Client.ftpClient, Client.remoteDirectory, Client.view_hidden); } result = action.Run(); History.Log(result.ToString()); if (result is DFtpListResult) { DFtpListResult listResult = (DFtpListResult)result; foreach (DFtpFile file in listResult.Files) { if (file.Type() == FtpFileSystemObjectType.File) { ConsoleUI.WriteLine((file.ToString()), Color.Green); } else if (file.Type() == FtpFileSystemObjectType.Directory) { ConsoleUI.WriteLine((file.ToString()), Color.Orange); } } } }
public DFtpResult Go() { String pattern = IOHelper.AskString("What pattern to search for?"); bool searchRecursive = IOHelper.AskBool("Include subdirectories?", "yes", "no"); //create an action and initialize with the info we have collected DFtpAction action = new SearchFileLocalAction(pattern, Client.localDirectory, searchRecursive); DFtpResult result = action.Run(); //check if the file is present in the list if (typeof(DFtpListResult).IsInstanceOfType(result)) { DFtpListResult listResult = (DFtpListResult)result; IOHelper.Select <DFtpFile>("Search Result:", listResult.Files, true); } else { bool searchAgain = IOHelper.AskBool("Unable to find any file with pattern: " + pattern + ". Do you want to search again?", "yes", "no"); if (searchAgain) { Go(); } } return(result); }
public DFtpResult Go() { // Get listing for remote directory DFtpAction getListingAction = new GetListingRemoteAction(Client.ftpClient, Client.remoteDirectory, Client.view_hidden); DFtpResult tempResult = getListingAction.Run(); DFtpListResult listResult = null; if (tempResult is DFtpListResult) { listResult = (DFtpListResult)tempResult; // Choose from files DFtpFile selected = IOHelper.Select <DFtpFile>("Choose a remote file to select.", listResult.Files, true); // If something has been selected, update the remote selection if (selected != null) { Client.remoteSelection = selected; return(new DFtpResult(DFtpResultType.Ok, "Selected file/dir '" + Client.remoteSelection + "'.")); } else { return(new DFtpResult(DFtpResultType.Ok, "Cancelled")); } } return(tempResult); }
public void GetMultipleTest() { EstablishConnection(); if (client.DirectoryExists(RemoteTestDirectory)) { client.DeleteDirectory(RemoteTestDirectory); } List <DFtpFile> files = new List <DFtpFile>(); // Create and put 3 files on server. for (int i = 0; i < 3; ++i) { files.Add(CreateAndPutFileInDirectoryOnServer(client)); } // Get multiple files from the directory DFtpAction listingAction = new GetListingRemoteAction(client, RemoteTestDirectory, true); DFtpResult tempList = listingAction.Run(); DFtpListResult listResult = null; if (tempList is DFtpListResult) { listResult = (DFtpListResult)tempList; List <DFtpFile> list = listResult.Files.Where(x => x.Type() == FtpFileSystemObjectType.File).ToList(); DFtpAction action = new GetMultipleAction(client, LocalTestDirectory, list); DFtpResult result = action.Run(); if (result is DFtpListResult) { listResult = (DFtpListResult)result; Assert.True(listResult.Files.Count == 3); } else { return; } } else { return; } foreach (DFtpFile file in files) { // Delete each file RemoveFileOnServer(client, file); // Make sure it's gone Assert.False(SearchForFileOnServer(client, file.GetName())); } if (client.DirectoryExists(RemoteTestDirectory)) { client.DeleteDirectory(RemoteTestDirectory); } return; }
public void DrawResultList(DFtpListResult list) { Console.WriteLine(); foreach (DFtpFile file in list.Files) { Console.WriteLine(file.GetName() + " " + file.GetSize() + " " + (file.Type() == FluentFTP.FtpFileSystemObjectType.Directory? "dir" : "file")); } Console.WriteLine(); return; }
public void GetListingRemoteTest() { EstablishConnection(); List <DFtpFile> directory = new List <DFtpFile>(); String Remotedir = "/Test"; CreatedeepDir(client); // Get listing of the directory DFtpAction action = new GetListingRemoteAction(client, Remotedir, true); DFtpResult result = action.Run(); DFtpListResult listResult = null; if (result is DFtpListResult) { listResult = (DFtpListResult)result; var directories = listResult.Files.Where(x => x.Type() == FtpFileSystemObjectType.Directory); //.Type() == FtpFileSystemObjectType.Directory); var cnt = directories.ToList().Count; //Console.Write("directories:"+cnt); Assert.True(cnt == 3); } else { return; } client.DeleteDirectory("/Test", FtpListOption.AllFiles); // Check that there are three files //Assert.True(listResult.Equals(directory)); // foreach (DFtpFile file in files) // { // // Delete each file // //RemoveFileOnServer(client, file); // RemoveDirectoryOnServer(client, ) // { // } // // Make sure it's gone // Assert.False(SearchForFileOnServer(client, file.GetName())); // } // return; }
public void GetListingRemoteTest() { EstablishConnection(); List <DFtpFile> directory = new List <DFtpFile>(); // Create and put 3 files on server. for (int i = 0; i < 3; ++i) { //files.Add(CreateAndPutFileInDirectoryOnServer(client)); directory.Add(CreateAndPutDirectoryOnServer(client)); } // Get listing of the directory DFtpAction action = new GetListingRemoteAction(client, testDirectory); DFtpResult result = action.Run(); DFtpListResult listResult = null; if (result is DFtpListResult) { listResult = (DFtpListResult)result; var directories = listResult.Files.Where(x => x.Type() == FtpFileSystemObjectType.Directory); //.Type() == FtpFileSystemObjectType.Directory); var cnt = directories.ToList().Count; //Assert.True(cnt == 3); } else { return; } // Check that there are three files //Assert.True(listResult.Equals(directory)); // foreach (DFtpFile file in files) // { // // Delete each file // //RemoveFileOnServer(client, file); // RemoveDirectoryOnServer(client, ) // { // } // // Make sure it's gone // Assert.False(SearchForFileOnServer(client, file.GetName())); // } return; }
public void GetListingRemoteTest() { EstablishConnection(); if (client.DirectoryExists(testDirectory)) { client.DeleteDirectory(testDirectory); } List <DFtpFile> files = new List <DFtpFile>(); // Create and put 3 files on server. for (int i = 0; i < 3; ++i) { files.Add(CreateAndPutFileInDirectoryOnServer(client)); } // Get listing of the directory DFtpAction action = new GetListingRemoteAction(client, testDirectory); DFtpResult result = action.Run(); DFtpListResult listResult = null; if (result is DFtpListResult) { listResult = (DFtpListResult)result; } else { return; } // Check that there are three files Assert.True(listResult.Files.Count == 3); foreach (DFtpFile file in files) { // Delete each file RemoveFileOnServer(client, file); // Make sure it's gone Assert.False(SearchForFileOnServer(client, file.GetName())); } if (client.DirectoryExists(testDirectory)) { client.DeleteDirectory(testDirectory); } return; }
public void GetListingLocal() { DFtpAction action = new GetListingLocalAction(LocalTestDirectory); DFtpResult result = action.Run(); DFtpListResult lresult = null; if (result is DFtpListResult) { lresult = (DFtpListResult)result; } else { return; } Assert.True(lresult.Files.Count >= 1); }
public DFtpResult Go() { // Get listing for remote directory DFtpAction getListingAction = new GetListingRemoteAction(Client.ftpClient, Client.remoteDirectory, Client.view_hidden); DFtpResult tempResult = getListingAction.Run(); if (tempResult.Type == DFtpResultType.Ok) { DFtpListResult listResult = null; if (tempResult is DFtpListResult) { listResult = (DFtpListResult)tempResult; List <DFtpFile> list = listResult.Files.Where(x => x.Type() == FtpFileSystemObjectType.File).ToList(); List <DFtpFile> selected = new List <DFtpFile>(); selected = IOHelper.SelectMultiple("Select multiple files to download!(Arrow keys navigate, spacebar selects/deselects, enter confirms the current selection.)", list, false); if (selected.Count == 0) { IOHelper.Message("No files selected."); return(new DFtpResult(DFtpResultType.Ok)); } DFtpAction action = new GetMultipleAction(Client.ftpClient, Client.localDirectory, selected); // Carry out the action and get the result DFtpResult result = action.Run(); // Give some feedback if successful if (result.Type == DFtpResultType.Ok) { IOHelper.Message("files downloaded successfully."); } return(result); } else { return(new DFtpResult(DFtpResultType.Error, "Error on the operation.")); } } else { return(new DFtpResult(DFtpResultType.Error, "Error on the operation.")); } }
public DFtpResult Go() { // Get listing for remote directory DFtpAction getListingAction = new GetListingLocalAction(Client.localDirectory); DFtpResult tempResult = getListingAction.Run(); DFtpListResult listResult = null; if (tempResult is DFtpListResult) { listResult = (DFtpListResult)tempResult; DFtpFile selected = IOHelper.Select <DFtpFile>("Choose a local file to select.", listResult.Files, true); // If something has been selected, update the remote selection if (selected != null) { Client.localSelection = selected; return(new DFtpResult(DFtpResultType.Ok, "Selected file/dir '" + Client.remoteSelection + "'.")); } } return(tempResult); }
public void SearchFileExistsDeepSearch() { EstablishConnection(); String remoteDirectory = "/way/down/here/in/deep/folder/"; // 1. Create and put file on server. DFtpFile tempFile = CreateAndPutFileOnServer(client, remoteDirectory); // 2. Force a recursive search action. DFtpAction action = new SearchFileRemoteAction(client, tempFile.GetName(), "/", true); DFtpListResult result = (DFtpListResult)action.Run(); // 3. Delete file. RemoveFileOnServer(client, tempFile, remoteDirectory); // 4. Delete Directories. client.DeleteDirectory("/way", FtpListOption.AllFiles); Assert.True(result.Type == DFtpResultType.Ok && result.Files.Count == 1 && result.Files[0].GetName() == tempFile.GetName()); return; }
/// <summary> /// Displays a list of possible directories to enter, then changes the client to the selected directory. /// </summary> /// <returns>Returns a DFtpResult indicating success or failure.</returns> public DFtpResult Go() { // Get listing for current directory if (Client.state == ClientState.VIEWING_REMOTE) { DFtpAction getListingAction = new GetListingRemoteAction(Client.ftpClient, Client.remoteDirectory); DFtpResult tempResult = getListingAction.Run(); DFtpListResult listResult = null; if (tempResult is DFtpListResult) { listResult = (DFtpListResult)tempResult; List <DFtpFile> list = listResult.Files; // Filter out files list = list.Where(x => x.Type() == FtpFileSystemObjectType.Directory).ToList(); // Choose from directories DFtpFile selection = IOHelper.Select <DFtpFile>("Choose a directory to enter.", list, true); // If something has been selected, update the remote selection if (selection != null) { Client.remoteSelection = null; Client.remoteDirectory = selection.GetFullPath(); return(new DFtpResult(DFtpResultType.Ok, "Changed to directory '" + Client.remoteDirectory + "'.")); } } return(tempResult); } else if (Client.state == ClientState.VIEWING_LOCAL) { // Get listing for current directory DFtpAction action = new GetListingLocalAction(Client.localDirectory); DFtpResult result = action.Run(); DFtpListResult listResult = null; if (result is DFtpListResult) { listResult = (DFtpListResult)result; List <DFtpFile> list = listResult.Files; // Filter out files list = list.Where(x => x.Type() == FtpFileSystemObjectType.Directory).ToList(); // Choose from directories DFtpFile selection = IOHelper.Select <DFtpFile>("Choose a directory to enter.", list, true); // If something has been selected, update the local selection if (selection != null) { Client.localSelection = null; if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { if (Client.localDirectory.EndsWith("\\")) { Client.localDirectory = Client.localDirectory + selection.GetName(); } else { Client.localDirectory = Client.localDirectory + @"\" + selection.GetName(); } } else { Client.localDirectory = Client.localDirectory + "/" + selection; } return(new DFtpResult(DFtpResultType.Ok, "Changed to directory '" + Client.localDirectory + "'.")); } } return(result); } else { return(new DFtpResult(DFtpResultType.Error, "Error on changing directory.")); } }