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() { // 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; }
internal void GetDirectoryFromRemoteServer(FtpClient ftpClient, String remoteDirectory = testDirectory) { //DFtpFile remoteSelection = file; DFtpAction action = new GetListingRemoteAction(ftpClient, remoteDirectory, true); DFtpResult result = action.Run(); 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 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.")); } }
/// <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.")); } }