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

            DFtpResult result = action.Run();

            return(result.Type == DFtpResultType.Ok ? true : false);
        }
        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 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);
        }
        public void SearchFileExistsDeepSearchNotIncludeSubDirectories()
        {
            EstablishConnection();
            String remoteDirectory = "/way/down/here/in/deep/folder/";

            // 1. Create and put file on server.
            DFtpFile tempFile = CreateAndPutFileOnServer(client, remoteDirectory);

            // 2. This should return error, because the file is deep within a directory tree and
            // we are searching the root directory, non-recursively.
            bool       recursiveSearch = false;
            DFtpAction action          = new SearchFileRemoteAction(client, tempFile.GetName(), "/", recursiveSearch);

            DFtpResult result = action.Run();

            // 3. Delete file.
            RemoveFileOnServer(client, tempFile, remoteDirectory);

            // 4. Delete Directory.
            client.DeleteDirectory("/way", FtpListOption.AllFiles);

            Assert.True(result.Type == DFtpResultType.Error);
            return;
        }
        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;
        }