Ejemplo n.º 1
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;
        }
Ejemplo n.º 2
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."));
            }
        }