Setting Remove to True in GetFiles removes the whole direct
I am using the latest version of WinSCP, and I am using the .NET assemblies.
In the transferOptions, I set the FileMask. When I get files using the session.GetFiles, and set the Remove parameter to True, it works fine if there is only one file in the directory (and it removes the correct one). However, if there is only the one file in the directory, it removes the file AND the directory. How can I prevent it from removing the directory? The filemask in the code below is being set to ODS*.txt.
In the transferOptions, I set the FileMask. When I get files using the session.GetFiles, and set the Remove parameter to True, it works fine if there is only one file in the directory (and it removes the correct one). However, if there is only the one file in the directory, it removes the file AND the directory. How can I prevent it from removing the directory? The filemask in the code below is being set to ODS*.txt.
SessionOptions sessionOptions = new SessionOptions(); if (job.ConnectionType == "sftp") { sessionOptions.Protocol = Protocol.Sftp; sessionOptions.GiveUpSecurityAndAcceptAnySshHostKey = true; } sessionOptions.HostName = job.FTPAddress; sessionOptions.PortNumber = Convert.ToInt32(job.port); sessionOptions.UserName = job.Username; sessionOptions.Password = job.Password; using (Session session = new Session()) { // Connect session.Open(sessionOptions); // Upload files TransferOptions transferOptions = new TransferOptions(); transferOptions.TransferMode = TransferMode.Binary; transferOptions.FileMask = job.PickUpDirectoryMask; TransferOperationResult transferResult = null; if (job.FTPType == "get") { if (session.FileExists(job.PickUpDirectory)) { transferResult = session.GetFiles(job.PickUpDirectory, job.DropOffDirectory, true, transferOptions); } else { LogFTPStatus(job.JobId, false, "Scheduled", "Fail - File does not exist.", log); } } else { if (session.FileExists(job.PickUpDirectory)) { transferResult = session.PutFiles(job.PickUpDirectory, job.DropOffDirectory, true, transferOptions); } else { LogFTPStatus(job.JobId, false, "Scheduled", "Fail - File does not exist.", log); } } if (transferResult != null) { if (transferResult.IsSuccess) { //The transfer can still look like a success even if no files were transfered. Not sure why if (transferResult.Transfers.Count >= 1) { LogFTPStatus(job.JobId, true, "Scheduled", "Success", log); } else if(transferResult.Transfers.Count == 0) { LogFTPStatus(job.JobId, false, "Scheduled", "Fail - File does not exist.", log); } } else { transferResult.Check(); LogFTPStatus(job.JobId, false, "Scheduled", "Fail", log); log.WriteEntry("Failures were: " + transferResult.Failures.ToString()); } } } } else { log.WriteEntry("No transfers to run"); } } catch (Exception e) { //Write the exception to the event log log.WriteEntry("Error in FTP Transfer: " + e); //Write the exception to the system log LogFTPStatus(job.JobId, false, "Scheduled", e.InnerException.ToString(), log); }