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);
        }
Esempio n. 3
0
        internal void DeleteLocalFile(DFtpFile localSelection)
        {
            DFtpAction action = new DeleteFileLocalAction(localSelection);
            DFtpResult result = action.Run();

            return;
        }
Esempio n. 4
0
        public void CreateDirectoryTest()
        {
            EstablishConnection();

            String directoryName = "temporary_test_directory";

            // Create directory
            DFtpAction action = new CreateDirectoryRemoteAction(client, directoryName);
            DFtpResult result = action.Run();

            // Check for error
            Assert.True(result.Type == DFtpResultType.Ok);

            // Get listing and check that directory exists
            FtpListItem[] files = client.GetListing("/");
            bool          found = false;

            foreach (FtpListItem item in files)
            {
                if (item.Name == directoryName)
                {
                    found = true;
                }
            }
            Assert.True(found);

            client.DeleteDirectory("/" + directoryName);

            return;
        }
Esempio n. 5
0
        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);
                    }
                }
            }
        }
Esempio n. 6
0
        internal void CreateDirectoryLocal(FtpClient ftpClient, String directoryPath)
        {
            DFtpAction action = new CreateDirectoryLocalAction(client, directoryPath);
            DFtpResult result = action.Run();

            return;
        }
Esempio n. 7
0
        internal void RenameFileOnServer(FtpClient ftpClient, DFtpFile file, String newName)
        {
            DFtpFile   remoteSelection = file;
            DFtpAction action          = new RenameFileRemoteAction(ftpClient, test_Dir, remoteSelection, newName);
            DFtpResult result          = action.Run();

            return;
        }
        internal bool SearchForFileOnServer(FtpClient ftpClient, String pattern)
        {
            DFtpAction action = new SearchFileRemoteAction(ftpClient, pattern, "/");

            DFtpResult result = action.Run();

            return(result.Type == DFtpResultType.Ok ? true : false);
        }
        internal void RemoveFileOnServer(FtpClient ftpClient, DFtpFile file)
        {
            DFtpAction action = new DeleteFileRemoteAction(ftpClient, file.GetFullPath(), file);

            DFtpResult result = action.Run();

            return;
        }
        internal void RenameLocalFile(FtpClient ftpClient, DFtpFile file, String newName)
        {
            DFtpFile   localSelection = file;
            DFtpAction action         = new RenameFileLocalAction(ftpClient, test_Dir, localSelection, newName);
            DFtpResult result         = action.Run();

            return;
        }
Esempio n. 11
0
        public void NewDFtpResultContructor_PublicMethodsReturnsMatchingParameters(DFtpResultType resultType, String msg)
        {
            DFtpResult result = new DFtpResult(resultType, msg);

            Assert.True(result.Type == resultType);
            Assert.True(result.Message == msg);
            return;
        }
Esempio n. 12
0
        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;
        }
Esempio n. 13
0
        internal void RemoveFileOnServer(FtpClient ftpClient, DFtpFile file)
        {
            DFtpFile remoteSelection = file;

            DFtpAction action = new DeleteFileRemoteAction(ftpClient, test_Dir, remoteSelection);

            DFtpResult result = action.Run();

            return;
        }
        internal void GetDirectoryFromRemoteServer(FtpClient ftpClient, String remoteDirectory = testDirectory)
        {
            //DFtpFile remoteSelection = file;

            DFtpAction action = new GetListingRemoteAction(ftpClient, remoteDirectory, true);

            DFtpResult result = action.Run();

            return;
        }
        internal void RemoveDirectoryOnServer(FtpClient ftpClient, String remoteDirectory = testDirectory)
        {
            //DFtpFile remoteSelection = remoteDirectory;

            DFtpAction action = new DeleteRemoteDirectoryAction(ftpClient, remoteDirectory);

            DFtpResult result = action.Run();

            return;
        }
        internal void RemoveFileOnServer(FtpClient ftpClient, DFtpFile file, String remoteDirectory = "/")
        {
            DFtpFile remoteSelection = file;

            DFtpAction action = new DeleteFileRemoteAction(ftpClient, remoteDirectory, remoteSelection);

            DFtpResult result = action.Run();

            return;
        }
        internal void GetFileFromRemoteServer(FtpClient ftpClient, String localDirectory, DFtpFile file, String remoteDirectory = "/")
        {
            DFtpFile remoteSelection = file;

            DFtpAction action = new GetFileFromRemoteServerAction(ftpClient, localDirectory, remoteDirectory, remoteSelection);

            DFtpResult result = action.Run();

            return;
        }
        internal DFtpFile CreateAndPutDirectoryOnServer(FtpClient ftpClient, String remoteDirectory = testDirectory)
        {
            String dirpath = Path.GetDirectoryName(remoteDirectory);
            //String localDirectory = Path.GetDirectoryName(filepath);
            DFtpFile localSelection = new DFtpFile(dirpath, FtpFileSystemObjectType.Directory);

            DFtpAction action = new CreateDirectoryRemoteAction(client, dirpath);

            DFtpResult result = action.Run();

            return(localSelection);
        }
Esempio n. 19
0
        internal DFtpFile CreateAndPutFileInDirectoryOnServer(FtpClient ftpClient, String remoteDirectory = testDirectory)
        {
            String   filepath       = Path.GetTempFileName();
            String   localDirectory = Path.GetDirectoryName(filepath);
            DFtpFile localSelection = new DFtpFile(filepath, FtpFileSystemObjectType.File);

            DFtpAction action = new PutFileAction(client, localDirectory, localSelection, remoteDirectory);

            DFtpResult result = action.Run();

            return(localSelection);
        }
        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 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);
        }
Esempio n. 22
0
        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;
        }
        internal bool ChmodFileOnServer(FtpClient ftpClient, String remoteDirectory, DFtpFile remoteSelection, int permissions)
        {
            DFtpAction action = new ChmodFileRemoteAction(ftpClient, remoteDirectory, remoteSelection, permissions);
            DFtpResult result = action.Run();

            if (result.Type == DFtpResultType.Ok)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        public void SearchFileNotExists()
        {
            EstablishConnection();

            // Some random new file path.
            String filepath = Path.GetTempFileName();

            // A random file really shouldnt exist on the server.
            DFtpAction action = new SearchFileRemoteAction(client, filepath, "/");

            DFtpResult result = action.Run();

            Assert.True(result.Type == DFtpResultType.Error);
        }
Esempio n. 25
0
        /// <summary>
        /// Attemps to upload a file from the client context to the remote server.
        /// </summary>
        /// <returns>A DftpResult object containing an OK or ERROR with a message of the
        /// resulting operation.</returns>
        public DFtpResult Go()
        {
            // Create the action. Initialize it with the info we've collected
            DFtpAction action = new PutFileAction(Client.ftpClient, Client.localDirectory, Client.localSelection, Client.remoteDirectory);

            DFtpResult result = action.Run();

            // Give some feedback if successful
            if (result.Type == DFtpResultType.Ok)
            {
                IOHelper.Message("The file '" + Client.localSelection.GetName() + "' uploaded successfully.");
            }
            // Return the result after running.
            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);
        }
Esempio n. 27
0
        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;
        }
Esempio n. 28
0
        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);
        }
Esempio n. 29
0
        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."));
            }
        }
Esempio n. 30
0
        public DFtpResult Go()
        {
            // Create the action
            // Initialize it with the info we've collected
            DFtpAction action = new DeleteFileRemoteAction(Client.ftpClient, Client.remoteDirectory, Client.remoteSelection);

            // Carry out the action and get the result
            DFtpResult result = action.Run();

            // Nullify the selection if successful.
            if (result.Type == DFtpResultType.Ok)
            {
                IOHelper.Message("The file '" + Client.remoteSelection.GetName() + "' was deleted successfully.");
                Client.remoteSelection = null;
            }

            return(result);
        }