Topic "Setting Remove to True in GetFiles removes the whole direct"

Author Message
andrewkc69
[View user's profile]

Joined: 2015-03-27
Posts: 6
Location: Portland
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.

Code:

 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);
            }
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
Duplicate post:
https://winscp.net/forum/viewtopic.php?t=15133
_________________
Martin Prikryl
andrewkc69
[View user's profile]

Joined: 2015-03-27
Posts: 6
Location: Portland
prikryl wrote:


Martin,
This is not a duplicate post. At least it's not a duplicate to the one you linked to. This one is about setting the True flag in the GetFiles method and the other one is about using FileMask. Just because I used the same code in both topics, you are calling it a duplicate?? Did you read the issue, or am I missing how the FileMask and GetFiles issues are related?? I used the same code in both posts because they were separate issues. If I am missing something else here that makes them duplicates, please help me understand.

Thanks,
Andy
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 25015
Location: Prague, Czechia
Sorry, I didn't notice the difference.

Please attach a full session log file showing the problem (using the latest version of WinSCP).

To generate log file, set Session.SessionLogPath. Submit the log with your post as an attachment. Note that passwords and passphrases not stored in the log. You may want to remove other data you consider sensitive though, such as host names, IP addresses, account names or file names (unless they are relevant to the problem). If you do not want to post the log publicly, you can mark the attachment as private.
_________________
Martin Prikryl
Advertisements

You can post new topics in this forum






Search Site

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License