sftp

Post any questions you have about using the Verj.io Studio, including client and server-side programming with Javascript or FPL, and integration with databases, web services etc.

Moderators: Jon, Steve, Ian, Dave

HarryDeBoer
Ebase User
Posts: 118
Joined: Tue Oct 23, 2012 7:01 am
Location: The Netherlands

sftp

#1

Postby HarryDeBoer » Mon Aug 04, 2014 6:48 am

Hi,

1:
in the FAQ is read that ftp is available as a resource. I don't see that however in the Designer.

2:
What about sftp?
0 x
Kind regards,

Harry

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#2

Postby Jon » Mon Aug 04, 2014 7:35 am

Harry,

1. We have a Custom Resource that can be used for ftp. It's supplied on an "as is" basis and not officially supported. If you're interested please send an email to support (support@ebasetech.com).

2. We don't have anything for sftp. I see there is a Java library from Apache commons that supports this and I would advise using this. You can call this directly from a Javascript script.

Regards
Jon
0 x

HarryDeBoer
Ebase User
Posts: 118
Joined: Tue Oct 23, 2012 7:01 am
Location: The Netherlands

#3

Postby HarryDeBoer » Mon Aug 04, 2014 12:24 pm

Hi Jon,

Thanks. Would it also be possible to execute or call a batch file (or maybe even an exec -on the same machine (hardware) where the Ebase server resides) from where we can start an sftp session (ie winsftp).
0 x
Kind regards,

Harry

Jon
Moderator
Moderator
Posts: 1342
Joined: Wed Sep 12, 2007 12:49 pm

#4

Postby Jon » Mon Aug 04, 2014 12:50 pm

Yes, it's possible, but again you need to use Java code to do this. Type it into google and you will see many examples. Executing .bat and .exe files is supported in native Java and there is also an Apache commons library http://commons.apache.org/proper/common ... index.html.

You might find it's less work to use the Apache sftp package. I've never done this, so hard to judge which is the best route.

Regards
Jon
0 x

Dave
Ebase Staff
Posts: 89
Joined: Mon Sep 10, 2007 11:48 am

#5

Postby Dave » Wed Aug 06, 2014 12:41 pm

Hi Harry,

I've used the Apache Commons library for FTP (not SFTP though), but I imagine it's very similar. Here's a bit of sample code:

Code: Select all

importPackage(com.ebasetech.xi.api);
importPackage(com.ebasetech.xi.services);
importPackage(java.io);
importPackage(org.apache.commons.net.ftp);

// set up FTP connection
var c = new FTPClient();

// download files to master
var serversDL = tables.WZ_SERVERS.rows;
while (serversDL.next()) {
   if (tables.WZ_SERVERS.MASTER.value != 'Y') {
   	     // connect to servant's FTP server
	       writeLog(logName,'Connecting to FTP server on server ' + tables.WZ_SERVERS.SERVER_ID.value + '...','INFO');
	       c.connect(tables.WZ_SERVERS.DOMAIN.value);
	       c.login(tables.WZ_SERVERS.USERNAME.value, tables.WZ_SERVERS.PASSWORD.value);
	       writeLog(logName,'FTP connection successful','INFO');
	       
	       // get the list of files to be retrieved
	       writeLog(logName,'----------------------------','INFO');
	       writeLog(logName,'Getting file list for server '+tables.WZ_SERVERS.SERVER_ID.value,'INFO');
         var p = {};
         p.SYNCH_ID = fields.SYNCH_ID.value;
         p.SERVER_ID = tables.WZ_SERVERS.SERVER_ID.value;
         var rows = tables.WZ_SYNCH_FILELIST.findRows(p);
    
 	       // retrieve each file via FTP and write to master's local file system
 	       writeLog(logName,'Download of files from server '+tables.WZ_SERVERS.SERVER_ID.value+' begins','INFO');
         while (rows.next()) {
            // replace filename back slashes with forward slashes, remove the absolute path reference for the FTP call
            var fn = processFilenames(tables.WZ_SYNCH_FILELIST.FILENAME.value);
            var dlf = fn[0];
            var filename = fn[1];
            
            // set up output stream for file to be written locally
	          var fos = new FileOutputStream(filename);

	          // fetch the file from the FTP server
	          writeLog(logName,'Retrieving file ' + dlf + ' from server ' + tables.WZ_SERVERS.SERVER_ID.value + ' and updating master server','INFO');
            c.retrieveFile(dlf, fos);
	          writeLog(logName,'File retrieval and update successful','INFO');

	          // close output stream
            fos.close();
         }
	       c.disconnect();		
 	       writeLog(logName,'Download of files from server '+tables.WZ_SERVERS.SERVER_ID.value+' completed','INFO');
      }
   }
   writeLog(logName,'Download of all files from all servants to master completed','INFO');

writeLog(logName,'***********************************************************','INFO');
Sorry about the blah, blah in the code but hopefully you can see the basics around opening a connection to an FTP server and streaming files.

Very easy, all you need to do is add the Apache jars to tomcat/lib and you're away.

Cheers,
Dave
0 x

HarryDeBoer
Ebase User
Posts: 118
Joined: Tue Oct 23, 2012 7:01 am
Location: The Netherlands

#6

Postby HarryDeBoer » Thu Aug 07, 2014 1:12 pm

Thanks Dave, very helpfull.
0 x
Kind regards,

Harry


Who is online

Users browsing this forum: No registered users and 21 guests