Sidebar

How to read file from FTP server with comma in file name using qie.readsftpFile

0 votes
228 views
asked Jan 20, 2023 by sowmya-l-3811 (140 points)
The below code is not able to retrive the file

var file = qie.readSFTPFile(sftpHost, sftpPort, filePath, deleteFiles, null, true, true, params, userName, password, 60000);

1 Answer

0 votes

There are two workarounds for this situation.  The first is to replace the comma (or other special character) with a wildcard asterisk, which will allow the standard call to work.  The second is to use an Apache Camel parameter called include() to specify the filename.

To use the wildcard replacement method, you would use code similar to this:

// Start with the filename in a variable
var fileName = 'test,comma.txt';

// Replace all instances of a comma with an asterisk
var wildcardFileName = StringUtils.replace(fileName, ',', '*');

// Make the SFTP call to retrieve the file
var file = qie.readSFTPFile(sftpHost, sftpPort, wildcardFileName, deleteFiles, null, true, true, params, userName, password, 60000);

 

The second method, using the Apache Camel include() filter can be done this way.  This uses the wildcard asterisk in the standard file path field, which causes QIE to start with a list of all the files at that location.  The include() filter in the parameters section limits what QIE actually operates on to just the one file specified

// Start with the filename in a variable
var fileName = 'test,comma.txt');

// Make the SFTP call, using the filename variable in a Camel include() parameter
var file = qie.readSFTPFile(sftpHost, sftpPort, '*', deleteFiles, null, true, true, 'include(RAW("' + fileName + '")', userName, password, 60000);

answered Jan 20, 2023 by jon-t-7005 (7,590 points)
...