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() { String pattern = IOHelper.AskString("What pattern to search for?"); bool includeSubdirectories = IOHelper.AskBool("Include subdirectories?", "yes", "no"); // Create the action, Initialize it with the info we've collected DFtpAction action = new SearchFileRemoteAction(Client.ftpClient, pattern, Client.remoteDirectory, includeSubdirectories); // Carry out the action and get the result DFtpResult result = action.Run(); return(result); }
public DFtpResult Go() { String newName = IOHelper.AskString("Enter name for the new Directory:"); DFtpAction action = new CopyDirectoryRemoteAction(Client.ftpClient, Client.localDirectory, Client.remoteDirectory, Client.remoteSelection, newName); DFtpResult result = action.Run(); if (result.Type == DFtpResultType.Ok) { IOHelper.Message("The directory was successfully copied to '" + newName + "'."); Client.remoteSelection = null; } return(result); }
public DFtpResult Go() { String newName = IOHelper.AskString("Enter replacement name:"); // Create the action // Initialize it with the info we've collected DFtpAction action = new RenameFileLocalAction(Client.ftpClient, Client.localDirectory, Client.localSelection, newName); // Carry out the action and get the result DFtpResult result = action.Run(); if (result.Type == DFtpResultType.Ok) { IOHelper.Message("The file was successfully renamed to '" + newName + "'."); Client.localSelection = null; } return(result); }
public DFtpResult Go() { String name = IOHelper.AskString("Enter new directory name."); // Create the action, Initialize it with the info we've collected DFtpAction action = new CreateDirectoryRemoteAction(Client.ftpClient, Client.remoteDirectory + "/" + name); // Carry out the action and get the result DFtpResult result = action.Run(); // Give some feedback if successful if (result.Type == DFtpResultType.Ok) { IOHelper.Message("The directory '" + name + "' was created successfully."); } // Return the result after running. return(result); }
public static bool TryConnect(String lastAttemptMessage = "") { ConnectionInformation connInfo = new ConnectionInformation("", ""); // Get input from user? bool newConnection = IOHelper.AskBool("Welcome to the DumbFTP Client " + lastAttemptMessage, "New connection", "Load saved connection"); if (newConnection) { // Server name String server = IOHelper.AskString("Enter server, or press [Enter] for 'Hypersweet.com'."); if (server == "") { server = "hypersweet.com"; } // User name String user = IOHelper.AskString("Enter username, or press [Enter] for 'cs410'."); if (user == "") { user = "******"; } connInfo = new ConnectionInformation(user, server); } else { List <ConnectionInformation> savedConnections = ConnectionInformation.GetAllSavedConnections(); if (savedConnections == null || savedConnections.Count == 0) { return(TryConnect("[No saved connections]")); } connInfo = IOHelper.Select <ConnectionInformation>("Which connection would you like?", ConnectionInformation.GetAllSavedConnections().ToArray(), true); } // Password String password = IOHelper.AskString("Enter password, or press [Enter] for 'cs410'."); if (password == "") { password = "******"; } // Connect the ftp client try { FtpClient client = new FtpClient(connInfo.ServerAddress) { Port = 21, Credentials = new NetworkCredential(connInfo.Username, password), }; client.Connect(); if (client.IsConnected) { Client.serverName = connInfo.ServerAddress; Client.ftpClient = client; } } catch (Exception e) { // Oh, jeeze. Client.ftpClient = null; Console.WriteLine("Could not connect to server: " + e.Message); } // See if the user wants to save this new connection. if (newConnection && IOHelper.AskBool("Would you like to save this connection information?", "yes", "no")) { new ConnectionInformation(connInfo.Username, connInfo.ServerAddress).Save(); } return(Client.ftpClient != null && Client.ftpClient.IsConnected); }