Sidebar

How to Create Dated Folder in SFTP

0 votes
802 views
asked Jul 7, 2015 by (170 points)

I have a working mapping node that creates a dated folder on a local network but I now need to change it to do the same for SFTP but I'm not sure how to change my existing code to do this.  Using information I found here I came up with the following code for creating the dated folder on a local network:

var fulldate = qie.getSystemDate();
var year = qie.formatDate('yyyy', fulldate);
var month = qie.formatDate('MM', fulldate);
var day = qie.formatDate('dd', fulldate);
var folder = "" + year + "-" + month + "-" + day;
 
var fullPath = qie.evaluateTemplate("\\\\Interface\\Archive\\"+folder+"\\");
 
var fullPathDirectory = new java.io.File(fullPath);
 
if (!fullPathDirectory.exists()) {
 
   fullPathDirectory.mkdirs();
 
}
 
messageCache.setValue('fullPath', fullPath);
I then use {c:fullPath}\*.* for the destination path.
 
How can I combine what I already have with the SFTP example to create a dated folder on the SFTP server and then write to that folder?

1 Answer

0 votes

Good question.  You can use an FTP Destination Node.  QIE uses Apache Camel FTP, which allows you to create the directory if it doesn't exist.  With "Interface" being your host server name, and your path being Archive\\{SYSTEM_DATE[yyyy-MM-dd]}\\*.*, your configuration would look something like this:

If your FTP server is a Linux machine, you would need to switch the direction of your directory slashes (from \\ to /), and change your parameter to  "separator=UNIX"

Also, FTP uses a login to the server, which will put you in a directory.  If Archive is your default directory for the user, you may not need to include that in your path.

answered Jul 7, 2015 by mike-r-7535 (13,830 points)
...