public void CreateChmodRemoveTest()
        {
            EstablishConnection();
            if (client.DirectoryExists(test_dir))
            {
                client.DeleteDirectory(test_dir, FtpListOption.AllFiles);
            }

            // 1. Create and put file on server.
            DFtpFile newFile = CreateAndPutFileOnServer(client, test_dir, "NewFile");

            // 2. Search for file, make sure that it exists.
            Assert.True(SearchForFileOnServer(client, test_dir, newFile.GetName()));

            // 3. Change the file permissions
            Assert.True(ChmodFileOnServer(client, test_dir, newFile, 777));

            // 4. Check the file permissions
            Assert.True(CheckChmodFileOnServer(client, test_dir, newFile, 777));

            // 5. Delete it
            client.DeleteFile(test_dir + "/" + newFile.GetName());

            // 6. We should NOT see the file on the server anymore
            Assert.False(SearchForFileOnServer(client, test_dir, newFile.GetName()));

            if (client.DirectoryExists(test_dir))
            {
                client.DeleteDirectory(test_dir, FtpListOption.AllFiles);
            }
            return;
        }
        public void CreatePutRenameRemoveTest()
        {
            EstablishConnection();
            if (client.DirectoryExists(test_Dir))
            {
                client.DeleteDirectory(test_Dir);
            }
            // 1. Create and put file on server.
            DFtpFile newFile = CreateAndPutFileOnLocal(client, test_Dir, "NewFile");

            // 2. Search for file, make sure that it exists.
            Assert.True(SearchForLocalFile(test_Dir, "NewFile"));

            // 3. Rename the file
            RenameLocalFile(client, newFile, "ChangedName");

            // 4. Ensure old name no longer exists
            Assert.False(SearchForLocalFile(test_Dir, "NewFile"));

            // 5. Search for the file by its new name
            Assert.True(SearchForLocalFile(test_Dir, "ChangedName"));

            // 6. Delete it
            File.Delete(test_Dir + "/ChangedName");

            // 7. We should NOT see the file on the server anymore
            Assert.False(SearchForLocalFile(test_Dir, "ChangedName"));
            if (client.DirectoryExists(test_Dir))
            {
                client.DeleteDirectory(test_Dir);
            }
            return;
        }
Esempio n. 3
0
        public void CreatePutRenameRemoveTest()
        {
            EstablishConnection();
            if (client.DirectoryExists(test_Dir))
            {
                client.DeleteDirectory(test_Dir);
            }
            // 1. Create and put file on server.
            DFtpFile newFile = CreateAndPutFileOnServer(client, "NewFile");

            // 2. Search for file, make sure that it exists.
            Assert.True(SearchForFileOnServer(client, newFile.GetName()));

            // 3. Rename the file
            RenameFileOnServer(client, newFile, "ChangedName");

            // 4. Search for the file by its new name
            Assert.True(SearchForFileOnServer(client, "ChangedName"));

            // 5. Old file should not still exist
            Assert.False(SearchForFileOnServer(client, "NewFile"));

            // 6. Delete it
            client.DeleteFile(test_Dir + "/ChangedName");

            // 7. We should NOT see the file on the server anymore
            Assert.False(SearchForFileOnServer(client, "ChangedName"));
            if (client.DirectoryExists(test_Dir))
            {
                client.DeleteDirectory(test_Dir);
            }
            return;
        }
        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. 5
0
        internal void DeleteLocalFile(DFtpFile localSelection)
        {
            DFtpAction action = new DeleteFileLocalAction(localSelection);
            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;
        }
        internal void RemoveFileOnServer(FtpClient ftpClient, DFtpFile file)
        {
            DFtpAction action = new DeleteFileRemoteAction(ftpClient, file.GetFullPath(), file);

            DFtpResult result = action.Run();

            return;
        }
Esempio n. 8
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;
        }
Esempio n. 9
0
        protected DFtpFile remoteSelection; // The remote file/directory selected when the action began

        /// <summary>
        /// This must be called before running the action to provide it with the client and
        /// current selection information.
        /// </summary>
        /// <param name="ftpClient">An already connected FtpClient object</param>
        /// <param name="localDirectory">The directory the user was viewing client-side</param>
        /// <param name="localSelection">The file/directory the user had selected client-side</param>
        /// <param name="remoteDirectory">The directory the user was viewing server-side</param>
        /// <param name="remoteSelection">The file/directory the user had selected server-side</param>
        public DFtpAction(FtpClient ftpClient, String localDirectory, DFtpFile localSelection, String remoteDirectory, DFtpFile remoteSelection)
        {
            this.ftpClient       = ftpClient;
            this.localDirectory  = localDirectory;
            this.localSelection  = localSelection;
            this.remoteDirectory = remoteDirectory;
            this.remoteSelection = remoteSelection;
        }
        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 void RemoveFileOnServer(FtpClient ftpClient, DFtpFile file, String remoteDirectory = "/")
        {
            DFtpFile remoteSelection = file;

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

            DFtpResult result = action.Run();

            return;
        }
Esempio n. 12
0
        internal void RemoveFileOnServer(FtpClient ftpClient, DFtpFile file)
        {
            DFtpFile remoteSelection = file;

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

            DFtpResult result = action.Run();

            return;
        }
Esempio n. 13
0
    public DFtpListResult(DFtpResultType type, String message, FtpListItem[] files) : base(type, message)
    {
        List <DFtpFile> list = new List <DFtpFile>();

        foreach (FtpListItem item in files)
        {
            DFtpFile file = new DFtpFile(item);
            list.Add(file);
        }
        this.Files = list;
    }
        internal DFtpFile CreateAndPutFileOnLocal(FtpClient ftpClient, String filePath, String newFileName)
        {
            DFtpFile localSelection = new DFtpFile(filePath + "/" + newFileName, FtpFileSystemObjectType.File, newFileName);

            Directory.CreateDirectory(filePath);
            FileStream newStream = File.Create(filePath + "/" + newFileName);

            newStream.Close();

            return(localSelection);
        }
        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. 16
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);
        }
        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);
            }
        }
Esempio n. 18
0
 public int CompareTo(DFtpFile other)
 {
     if (this.Type() == FtpFileSystemObjectType.Directory && other.Type() == FtpFileSystemObjectType.File)
     {
         return(-1);
     }
     else if (this.Type() == FtpFileSystemObjectType.File && other.Type() == FtpFileSystemObjectType.Directory)
     {
         return(1);
     }
     else
     {
         return(String.Compare(this.GetName(), other.GetName()));
     }
 }
        public void SearchFileExists()
        {
            EstablishConnection();

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

            // 2. Search for file, make sure that it exists.
            Assert.True(SearchForFileOnServer(client, tempFile.GetName()));

            // 3. Delete it
            RemoveFileOnServer(client, tempFile);

            return;
        }
        public void CreatePutDeleteTest()
        {
            // 1. Create and put file on local machine.
            DFtpFile tempFile = CreateFileOnLocal();

            // 2. Search for file, make sure that it exists.
            Assert.True(SearchForLocalFile(tempFile.GetFullPath()));

            // 3.  Delete the file
            DeleteLocalFile(tempFile);

            // 4. We should NOT see the file on the local machine anymore
            Assert.False(SearchForLocalFile(tempFile.GetFullPath()));

            return;
        }
        public void CreateAndPutFileOnServerSearchThenRemoveTest()
        {
            EstablishConnection();

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

            // 2. Search for file, make sure that it exists.
            Assert.True(SearchForFileOnServer(client, newFile.GetName()));

            // 3. Delete it
            RemoveFileOnServer(client, newFile);

            // 4. We should NOT see the file on the server anymore
            Assert.False(SearchForFileOnServer(client, newFile.GetName()));
            return;
        }
Esempio n. 22
0
        public void FileDiffFilesAreSame_FileDifFReturnsFalse()
        {
            EstablishConnection();
            System.Random random = new System.Random((int)Time.MillisecondsPastEquinox());

            // Create a file, put it on the server. Use FluentFTP to write this
            // byte sequence to the file.
            byte[] sequence = new byte[1024];
            random.NextBytes(sequence);

            DFtpFile file = CreateAndPutFileOnServer(client, "/");

            using (Stream ostream = client.OpenWrite(file.GetName()))
            {
                try
                {
                    ostream.Write(sequence, 0, sequence.Length);
                }
                finally
                {
                    ostream.Close();
                }
            }

            FtpReply reply = client.GetReply();

            // Download the file locally to the current working directory.
            client.DownloadFile(file.GetName(), file.GetName());

            // Compare the local selection with the remote selection.
            Client.localSelection  = new DFtpFile(file.GetName(), FtpFileSystemObjectType.File);
            Client.remoteSelection = new DFtpFile(file.GetName(), FtpFileSystemObjectType.File);


            // Same files should not be different.
            Assert.True(Client.AreFileSelectionsDifferent() == false);

            // Clean up
            File.Delete(file.GetName());
            client.DeleteFile(file.GetName());

            return;
        }
Esempio n. 23
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);
        }
        public void CopyDirTest()
        {
            EstablishConnection();
            //check if dir already exists
            if (client.DirectoryExists("/JTest"))
            {
                client.DeleteDirectory("/JTest", FtpListOption.AllFiles);
            }
            //set local and remote paths
            String localdir  = Path.GetTempPath();
            String Remotedir = "/";

            //create new directories with files
            CreatedeepDir(client);
            DFtpFile test = new DFtpFile("/Test", FtpFileSystemObjectType.Directory);

            //run the copy directory action
            DFtpAction action = new CopyDirectoryRemoteAction(client, localdir, Remotedir, test, "JTest");
            DFtpResult result = action.Run();

            //get the listings for all the directories we copied
            FtpListItem[] fluentListing  = client.GetListing("/JTest", FtpListOption.AllFiles);
            FtpListItem[] fluentListing2 = client.GetListing("/JTest" + "/test2", FtpListOption.AllFiles);
            FtpListItem[] fluentListing3 = client.GetListing("/JTest" + "/test3", FtpListOption.AllFiles);
            FtpListItem[] fluentListing4 = client.GetListing("/JTest" + "/test3" + "/tesst", FtpListOption.AllFiles);
            FtpListItem[] fluentListing5 = client.GetListing("/JTest" + "/test3" + "/tesst" + "/finaltest", FtpListOption.AllFiles);

            //compare the file numbers in each directory
            Assert.True(fluentListing.Length == 5);
            Assert.True(fluentListing2.Length == 4);
            Assert.True(fluentListing3.Length == 5);
            Assert.True(fluentListing4.Length == 6);
            Assert.True(fluentListing5.Length == 6);
            //clean up
            client.DeleteDirectory("/JTest", FtpListOption.AllFiles);
            client.DeleteDirectory("/Test", FtpListOption.AllFiles);

            //make sure everything is cleaned up
            Assert.False(client.DirectoryExists("/JTest"));
            Assert.False(client.DirectoryExists("/Test"));
        }
        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;
        }
Esempio n. 27
0
 /// <summary>
 /// Constructor to build an action that copies a directory on the server
 /// </summary>
 /// <param name="ftpClient"> The client connection to the server.</param>
 /// <param name="remoteDirectory">The remote directory path where the file to be renamed resides.</param>
 /// <param name="remoteSelection">The file to rename</param>
 /// <param name="localDirectory">"Current local directory for temp stoage"</param>
 /// <param name="newName">"New directory name"</param>
 ///
 public CopyDirectoryRemoteAction(FtpClient ftpClient, String localDirectory, String remoteDirectory, DFtpFile remoteSelection, String newName)
     : base(ftpClient, localDirectory, null, remoteDirectory, remoteSelection)
 {
     this.newName = newName;
 }
Esempio n. 28
0
        /// <summary>
        /// Constructor to build an action that renames a file on the ftp server.
        /// </summary>
        /// <param name="ftpClient"> The client connection to the server.</param>
        /// <param name="remoteDirectory">The remote directory path where the file to be renamed resides.</param>
        /// <param name="remoteSelection">The file to rename</param>

        public RenameFileRemoteAction(FtpClient ftpClient, String remoteDirectory, DFtpFile remoteSelection, String newName)
            : base(ftpClient, null, null, remoteDirectory, remoteSelection)
        {
            this.newName = newName;
        }
        /// <summary>
        /// Constructor to build an action that renames a file on local server.
        /// </summary>
        /// <param name="ftpClient"> The client connection to the server.</param>
        /// <param name="localDirectory">The local directory path where the file to rename resides.</param>
        /// <param name="localDirectory">The file to rename</param>

        public RenameFileLocalAction(FtpClient ftpClient, String localDirectory, DFtpFile localSelection, String newName)
            : base(null, localDirectory, localSelection, null, null)
        {
            this.newName = newName;
        }
Esempio n. 30
0
        internal DFtpFile CreateFileOnLocal()
        {
            DFtpFile tempFile = new DFtpFile(Path.GetTempFileName(), FtpFileSystemObjectType.File);

            return(tempFile);
        }