Issue with using -filemask to exclude sub-directories

Advertisement

Stan Brassell
Joined:
Posts:
3

Issue with using -filemask to exclude sub-directories

Hello,

I am attempting to exclude sub-directories (using –filemask) when retrieving files from a specified directory. I am putting together a script to be called by an SAP call to WinSCP. I want this script to be generic so that I can pass it any folder structure (via parameters passed in the SAP call).

Suppose the remote server directory structure is like the following:

/ (home or root directory)
/testA.txt
/OUT
/OUT/testB.txt
/OUT/next
/OUT/next/testC.txt

I want the chosen file to be written to a folder on my local server (\\Target\Subtarget).

* SCENARIO 1 (this works)
If I log in to the root/home level with an “open” command, use no “cd” command, and issue the following “get” command:
"get -filemask=|*/ * \\Target\Subtarget\"
Then only file testA.txt is retrieved and placed in the Subtarget sub-directory – as desired.

* SCENARIO 2 (this works)
If I log in to the root/home level with an “open” command, issue the following “cd” and “get” commands:
"cd /OUT"
"get -filemask=|*/ * \\Target\Subtarget\"
Then only file testB.txt is retrieved and placed in the Subtarget sub-directory – as desired.

* SCENARIO 3 (THIS FAILS)
If I log in to the root/home level with an “open” command, issue the following “cd” and “get” commands:
"cd /OUT/next"
"get -filemask=|*/ * \\Target\Subtarget\"
Then I am hoping to retrieve file testC.txt. However, nothing is retrieved, and the code executes much more quickly, indicating to me that it probably had an issue with the syntax. The error message I get back from the SAP call to WinSCP isn’t very informative.

Can someone tell me why this last scenario would fail, and how to resolve it?
Using WinSCP 5.5.4 on Windows 2008 R2.
The script being passed to the SAP call for SCENARIO 3 would be:
"open sftp://<username>:<password>@<host> -hostkey=""ssh-rsa 2048 xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx""" "cd /OUT/next" "get -filemask=|*/ * \\Target\Subtarget\" "close" "exit"

(the call to WinSCP would include option batch abort and option confirm off in addition to the script above)

Thanks.
Stan Brassell

Also... If I leave out the –filemask clause, the desired file is retrieved in SCENARIO 3 – but so are the unwanted subdirectories.

Reply with quote

Advertisement

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

Re: Issue with using -filemask to exclude sub-directories

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

To generate 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

Stan Brassell
Joined:
Posts:
3

Issue with using -filemask to exclude sub-directories

Sorry for the delay in replying; I got pulled onto something else.

Several unsuccessful attempts at adding a log statement led me to debug the SAP/ABAP side further, which led me to an explanation for (a) why the log command wouldn’t work, and (b) what caused the initial issues for which I entered this post.

The following explains a limitation of the SAP function module (that’s commonly used to externally call WinSCP), not an issue with the WinSCP application. I am including these notes in case they are of use to any ABAP developers planning to use WinSCP for SFTP.

SAP function module SXPG_COMMAND_EXECUTE has a parameter (additional_parameters) that can be used to pass commands (open, get, put, etc.). This parameter is defined as 255 characters, so it’s understood that those commands must add up to no longer than 255 characters. What wasn’t as obvious to me was that any other parameters that have been entered by way of transaction SM69 (Maintain External OS Commands) are lumped in with the additional parameters being explicitly fed to SXPG_COMMAND_EXECUTE. So, you have a maximum of 255 characters to use, for the additional parameters and the SM69-side parameters, combined.

So, my original issue was not caused by any limitation on the number of folder levels when using the –filemask clause. Rather, it was caused by a SAP-sourced limitation on the number of characters (in the commands) that can be fed to WinSCP via function module SXPG_COMMAND_EXECUTE.

Thanks for trying to help, Martin!

Reply with quote

Stan Brassell
Joined:
Posts:
3

Issue with using -filemask to exclude sub-directories

If executing WinSCP via SAP, you can get around the 255-character limitation mentioned above by using SAP function module SXPG_COMMAND_EXECUTE_LONG instead of SXPG_COMMAND_EXECUTE. If you use the "LONG" version, you can pass your commands to the long_params parameter (1024 character max) instead of the additional_parameters parameter (255 character max).

We're in the process of implementing an SFTP transmission for a client whose very long output file names would cause the combined commands to exceed 255 characters. In trying to resolve this issue, I found the SXPG_COMMAND_EXECUTE_LONG function module and have replaced a call to SXPG_COMMAND_EXECUTE with a call to its "LONG" equivalent.

Reply with quote

Advertisement

You can post new topics in this forum