I'm trying to download a file from an sftp site without deleting the file. The file I'm trying to download will always have today's date in the filename.
I couldn't see a way to do this using the standard sftp node, so I'm using the following custom script. My expectation is that when I execute the qie.readSFTPFile() function i'll be able to read the file without deleting it, but i'm getting an exception that says this:
Cannot rename file from: path/file-2020-08-14.csv to: path/file-2020-08-14.csv.camelExclusiveReadLock
This seems to indicate that the sftp call is attempting to move the file (though the source location is the same as the dest location). Is there a way to work around this without directly calling the camel sftp libraries myself?
var sftpHost = 'host.com';
var sftpPort = 22;
var userName = 'username';
var today = qie.formatDate('yyyy-MM-dd');
var currentFile = 'file-' + today + '.csv';
var fullPath = 'path/' + currentFile;
// note that i'm using camel params since my sftp uses a private key with a passphrase
var params = 'privateKeyFile=c:\\Keys\\myPrivateKey.ppk\nprivateKeyPassphrase=privateKeyPassphrase';
// get count of files in directory
qie.debug('Checking ' + fullPath);
var fileCount = 0;
try
{
// note that i'm using camel params since my sftp uses a private key with a passphrase
fileCount = qie.countSFTPEndpoint(sftpHost, sftpPort, fullPath, true, true, params, userName, null);
qie.debug('Count in ' + fullPath + ': ' + fileCount);
}
catch(err)
{
qie.error("Unable to enumerate files in " + fullPath + ": " + err);
}
if (fileCount === 1) {
try
{
var file = qie.readSFTPFile(sftpHost, sftpPort, fullPath, false, null, true, true, params, userName, null, 60000);
if(file !== null)
{
var encodedBytes = file.getNode('/ftpFile/encodedBytes');
var fileBytes = qie.base64DecodeToBytes(encodedBytes);
// add file to inbound queue
qie.addInboundMessage(fileBytes, currentFile);
}
else
{
qie.debug('Unable to process File: ' + fullPath);
}
}
catch(err)
{
qie.error("Unable to download recon files from source: " + err);
}
}
else
{
qie.error('There were ' + fileCount + ' files at source for the path [' + fullPath + '] instead of just 1 file.');
}