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 = 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 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; }
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; }
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; }
internal bool CheckChmodFileOnServer(FtpClient ftpClient, String remoteDirectory, DFtpFile remoteSelection, int permissions) { //GetChmod is bugged FtpListItem[] list = ftpClient.GetListing(remoteDirectory + "/" + remoteSelection.GetName()); int filePerms = list[0].Chmod; if (filePerms == permissions) { return(true); } else { return(false); } }
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 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; }
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; }
/// <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.")); } }