Put multiple files in one time from SFTP server

Hi all,

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 -

  1. Use \\folderPath\* in remoteFile and see what happens
  2. If #1 fails, then use “pub.client.sftp:cd” first to navigate to \\folderPath and then only use * in remoteFile
  3. 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.

KM

Hi @Venkata_Kasi_Viswanath_Mugada1,

I am really sorry I got that wrong!

What I really want to ask is to upload my local files to remote folder, so it is pub.client.sftp:put, not get.
Sorry to write the wrong depiction.

The correct flow is on 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:put : set localFile as fullFileName

Thank you again for your time.

Maggie

Similar story - there’s no mput for SFTP.

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.

KM

1 Like

Hi @Venkata_Kasi_Viswanath_Mugada1 ,

My IS version is 10.3.0.0.

Okay, I will follow these steps and try them.

Thank you for your reply!

Best Regards,
Maggie

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.