/// <summary> /// Compare the remote selection with the local selection within the client state. /// </summary> /// <returns>True, if the remote selection and the local selection are different.</returns> public static bool AreFileSelectionsDifferent() { if (ftpClient == null) // || !ftpClient.IsConnected) { throw new FtpException("FTP Client not found or is not connected"); } // Open the remote file. Stream remoteStream = ftpClient.OpenRead(remoteSelection.GetFullPath()); ftpClient.GetReply(); // to read the success/failure response from the server // Open the local file. using (Stream localStream = new FileStream(localSelection.GetFullPath(), FileMode.Open, FileAccess.Read)) { // Convert the local file and remote file streams to bytes. byte[] remoteBytes = remoteStream.ReadBytes(); byte[] localBytes = localStream.ReadBytes(); remoteStream.Close(); localStream.Close(); return((remoteBytes != null && localBytes != null) ? !remoteBytes.SequenceEqual(localBytes) : false); } }
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; }
internal void RemoveFileOnServer(FtpClient ftpClient, DFtpFile file) { DFtpAction action = new DeleteFileRemoteAction(ftpClient, file.GetFullPath(), file); DFtpResult result = action.Run(); 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.")); } }