Пример #1
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);
                    }
                }
            }
        }
Пример #2
0
        public void PutMultipleTest()
        {
            //Create and put 3 files on local machine.
            List <DFtpFile> files = new List <DFtpFile>();

            for (int i = 0; i < 3; ++i)
            {
                files.Add(CreateFileOnLocal());
            }

            // Get multiple files from the directory
            DFtpAction listingAction = new GetListingLocalAction(LocalTestDirectory, 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 PutMultipleAction(client, list, RemoteTestDirectory, true);
                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;
        }
Пример #3
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);
        }
Пример #4
0
        public DFtpResult Go()
        {
            // Get listing for remote directory
            DFtpAction getListingAction = new GetListingLocalAction(Client.localDirectory, 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 upload!(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 PutMultipleAction(Client.ftpClient, selected, Client.remoteDirectory, true);

                    // 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 uploaded successfully.");
                    }
                    return(result);
                }
                else
                {
                    return(new DFtpResult(DFtpResultType.Error, "Error on the operation."));
                }
            }


            else
            {
                return(new DFtpResult(DFtpResultType.Error, "Error on the operation."));
            }
        }
Пример #5
0
        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);
        }
Пример #6
0
        /// <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."));
            }
        }