I would like to upload many files to remote folder in one time from SFTP server, but there is only pub.client.sftp:get.
I try to set service-in parameter localFile as ‘\\folder_path\*’ by using regex. However, it failed.
And my another solution code is as below:
pub.file:listFiles: find all files in local folder and get the result ‘fileList’
Loop over fileList:
MAP: get full file name (local folder path + file name)
pub.client.sftp:get: set localFile as fullFileName
But it should setup the fileAccessControl configuration first.
Please suggest me the solution for this issue.
Thanks in advance.
There isn’t a built-in “mget” service for SFTP, but it does exist for FTP. You are experiencing a failure probably because you used “*” in localFile (this is for your filesystem) and instead of remoteFile (for the SFTP filesystem).
Having said that, I don’t recall how pub.client.sftp:get would behave if I tried to download multiple files. Can you try the following -
Use \\folderPath\* in remoteFile and see what happens
If #1 fails, then use “pub.client.sftp:cd” first to navigate to \\folderPath and then only use * in remoteFile
If either #1 or #2 are successful, then try expanding by using a file pattern now \\folderPath\filePattern* (example \\folderPath\Emp_*_2022*.csv)
Alternative - If all the above fail, then your alternative solution will work, but remember the difference between localFile vs remoteFile.
Libraries - Another way is to use a Java library (such as JSch, Apache Commons VFS, etc.), but I won’t recommend using libraries if you can achieve it with services and there’s a justifiable reason for their use.
You will have to use login to establish a session, (optionally use cd to navigate to the target folder) and then put. The sessionKey from the output of login, to all the other SFTP steps you’re invoking. You can form the remoteFile value (absolute/relative path including the filename) dynamically as you explained, and then use it.
You didn’t mention your wM version, but the SFTP services shouldn’t have changed much. Refer from page 115 in the built-in services guide here (link) to understand the services, their parameters and usage.