Cant Get Delete Functionality to Work Correctly

Advertisement

jdiesel33
Joined:
Posts:
7
Location:
Dallas, TX

Cant Get Delete Functionality to Work Correctly

Hello,
I have tried every way I can think of and cant get this to work like I want it to. I am using WinSCP in SSIS thru an Execute Process Task. Goal is to logon to an SFTP site, Get and then Delete any files of types .txt, .csv, .xls, or .xlsx that are 5 days old or older. No matter what I try, it either includes file types that I didnt specify like .ssh or.vb, or it moves and deletes folders that I am not even in. I have tried using CD right before the GET statement and also tried specifying the folder in the GET statement, but some reason it does not limit its search to the folder I specify. Also, if it doesnt find the folder that I specify, it just Gets and Deletes everything in the root folder that is 5 days or older. That is crazy. Here is what I used for my last 2 attempts:

get -delete -filemask= "*<5D" /FTP_ETLTEST01/Outbound/

get -delete -filemask= "*.txt<5D;*.xls<5D;*.csv<5D;*.xlsx<5D" /FTP_ETLTEST01/Outbound/

I typed those from memory, so I may be missing some punctuation. Not at my computer right now. However, both either moved and deleted file types that I did not specify or moved and deleted whole folders that were not in the folder I specified.

How can I write this statement so that it does what I want it to?

I am running Windows 7 Pro, Visual Studio 2012,and WinSCP 5.9.2.0, File Version 5.9.2.6958

Thanks in Advance!!!

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,454
Location:
Prague, Czechia

Re: Cant Get Delete Functionality to Work Correctly

You are missing a file mask at the end of source paths and there cannot be a space after the -filemask=:

get -delete -filemask="*<5D" /FTP_ETLTEST01/Outbound/*

get -delete -filemask="*.txt<5D;*.xls<5D;*.csv<5D;*.xlsx<5D" /FTP_ETLTEST01/Outbound/*

Though I'm not sure either would explain the behavior that you describe.

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

To generate the session log file, use /log=path_to_log_file command-line argument. 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.

Reply with quote

jdiesel33

Thanks for the assistance. This worked a little better, but it is still getting and deleting subfolders in the folder that I am specifying. Why would it even look at subfolders at all if I am specifying file types and what can I do to prevent this?

Thanks

Reply with quote

jdiesel33
Joined:
Posts:
7
Location:
Dallas, TX

Forgot. Here is what my new statement looks like:

get -delete -filemask="*.txt<5D";"*.csv<5D";"*.xls<5D";"*.xlsx<5D" /FTP_MMP_1522/Outbound/Kroger/*

and the log...

<filename value="/FTP_MMP_1522/Outbound/Kroger/Kroger_Activity_20170503_070136.txt" />
<destination value="\\cphs-fad-01\NetworkFileShare\DataLoads\FilesFromFTPs\FallOutFilesDelete\Kroger_Activity_20170503_070136.txt" />
<result success="true" />
</download>
<rm>
<filename value="/FTP_MMP_1522/Outbound/Kroger/Kroger_Activity_20170503_070136.txt" />
<result success="true" />
</rm>
<rm>
<filename value="/FTP_MMP_1522/Outbound/Kroger/ssh" />
<result success="true" />
</rm>
</session>

Reply with quote

Advertisement

jdiesel33
Joined:
Posts:
7
Location:
Dallas, TX

This is what I have as an argument in the SSIS task to create the log:

/log=\\CPHS-FAD-01\NetworkFileShare\IT\SSIS\DownloadAndStore\fallout_upload_list.xml

What do I need to do differently to create the log that you are requesting?

Thanks

Reply with quote

jdiesel33
Joined:
Posts:
7
Location:
Dallas, TX

Ok, log is attached. I figured out that it needed to be .log instead of .xml. Sorry about that.

So when I run it, there are no files in the folder that meet the time criteria of greater than 1 minute. There was a folder called SSH that was more than a minute old. It downloaded and then deleted the folder, even though i am only including file types .txt, .csv, .xls, and .xlsx in the filemask. How do i get it to only apply the get and delete to these files and not target folders as well?

Thanks
  • fallout_upload_list.log (5.27 KB, Private file)

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
41,454
Location:
Prague, Czechia

OK, I didn't realize you have subfolders (though I see now that you mentioned that before).

There's no way to prevent WinSCP script from deleting empty folders, when the -delete switch is specified.
You can only exclude a folder from both download and delete. But you cannot have it included in a download and exclude it from a delete.

For a solution, see
https://winscp.net/eng/docs/library_example_moves_files_keeping_directory_structure

Reply with quote

jdiesel33
Joined:
Posts:
7
Location:
Dallas, TX

"You can only exclude a folder from both download and delete. But you cannot have it included in a download and exclude it from a delete."
That is exactly what I want. I do not want it included in the download or in the delete. I want it to be ignored for everything. Is this link you sent the only way to do that?

Still not understanding when I am specifying specific file types, why anything outside of those file types would be included in the download or the delete.

Thanks

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
41,454
Location:
Prague, Czechia

jdiesel33 wrote:

That is exactly what I want. I do not want it included in the download or in the delete. I want it to be ignored for everything. ...

Still not understanding when I am specifying specific file types, why anything outside of those file types would be included in the download or the delete.
OK, then.
Do you want to exclude all subfolders? Or this one specifically?

To exclude all subfolders use:
get -delete -filemask="*.txt<5D;*.xls<5D;*.csv<5D;*.xlsx<5D|*/" /FTP_ETLTEST01/Outbound/*

The reason is that there is a separate set of filemasks for files and folders.

See https://winscp.net/eng/docs/file_mask#directory

Reply with quote

Advertisement

You can post new topics in this forum