Hi Phillip, oops, forgot to point out that there are quite a few Java solutions that allow you to use sftp. Using BSF4ooRexx allows you to use them with pure ooRexx, no need to code in Java yourself.
E.g. one solution uses <http://commons.apache.org/proper/commons-vfs/> (can be used from Java 1.5 on), so you would have to download that jar-file (jar="Java archive", a zip container of Java classes and sometimes with resources) and put its path into the environment variable named "CLASSPATH". Once on the CLASSPATH BSF4ooRexx can find all Java classes in that jar file and use them as if they were ooRexx classes. [The documentation for the Apache commons-vfs can be found here: <http://commons.apache.org/proper/commons-vfs/apidocs/index.html>.] The mentioned solution (uploading, downloading, deleting files using sftp) can be found here: <http://www.mysamplecode.com/2013/06/sftp-apache-commons-file-download.html>, so just read that page. Here is a transcription from the shown Java code to ooRexx (untested). Java-code for uploading a file via sftp: // Upload file to remote server using SFTP package com.as400samplecode; import java.io.File; import java.io.FileInputStream; import java.util.Properties; import org.apache.commons.vfs2.FileObject; import org.apache.commons.vfs2.FileSystemOptions; import org.apache.commons.vfs2.Selectors; import org.apache.commons.vfs2.impl.StandardFileSystemManager; import org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder; public class SendMyFiles { static Properties props; public static void main(String[] args) { SendMyFiles sendMyFiles = new SendMyFiles(); if (args.length < 1) { System.err.println("Usage: java " + sendMyFiles.getClass().getName()+ " Properties_file File_To_FTP "); System.exit(1); } String propertiesFile = args[0].trim(); String fileToFTP = args[1].trim(); sendMyFiles.startFTP(propertiesFile, fileToFTP); } public boolean startFTP(String propertiesFilename, String fileToFTP){ props = new Properties(); StandardFileSystemManager manager = new StandardFileSystemManager(); try { props.load(new FileInputStream("properties/" + propertiesFilename)); String serverAddress = props.getProperty("serverAddress").trim(); String userId = props.getProperty("userId").trim(); String password = props.getProperty("password").trim(); String remoteDirectory = props.getProperty("remoteDirectory").trim(); String localDirectory = props.getProperty("localDirectory").trim(); //check if the file exists String filepath = localDirectory + fileToFTP; File file = new File(filepath); if (!file.exists()) throw new RuntimeException("Error. Local file not found"); //Initializes the file manager manager.init(); //Setup our SFTP configuration FileSystemOptions opts = new FileSystemOptions(); SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking( opts, "no"); SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true); SftpFileSystemConfigBuilder.getInstance().setTimeout(opts, 10000); //Create the SFTP URI using the host name, userid, password, remote path and file name String sftpUri = "sftp://" + userId + ":" + password + "@" + serverAddress + "/" + remoteDirectory + fileToFTP; // Create local file object FileObject localFile = manager.resolveFile(file.getAbsolutePath()); // Create remote file object FileObject remoteFile = manager.resolveFile(sftpUri, opts); // Copy local file to sftp server remoteFile.copyFrom(localFile, Selectors.SELECT_SELF); System.out.println("File upload successful"); } catch (Exception ex) { ex.printStackTrace(); return false; } finally { manager.close(); } return true; } } The ooRexx transcription (untested) could look like this: -- Upload file to remote server using SFTP -- "main" method in a Java class can be used as the (prolog) Rexx code parse arg propertiesFile fileToFtp res=startFtp(propertiesFile, fileToFtp~strip) say "startFtp() returned:" res "(0=.false, 1=.true=success)" ::routine startFTP use arg propertiesFilename, fileToFTP props = .BSF~new("java.util.Properties") manager = .BSF~new("org.apache.commons.vfs2.impl.StandardFileSystemManager") -- no need to try and catch, if there is an error, the Rexx interpreter will abort -- and give the respective Java exception information props~load(.bsf~new("java.io.FileInputStream", "properties/"propertiesFilename)) serverAddress = props~getProperty("serverAddress" )~strip userID = props~getProperty("userId" )~strip password = props~getProperty("password" )~strip remoteDirectory = props~getProperty("remoteDirectory")~strip localDirectory = props~getProperty("localDirectory" )~strip -- check if the file exists filepath = localDirectory || fileToFTP file = .bsf~new("java.io.File", filepath) if \file~exists then raise syntax 90.900 array ("Error. Local file" pp(filepath) "not found") signal on syntax -- from now on let us intercept any condition to close manager and return .false -- Initializes the file manager manager~init -- Setup our SFTP configuration opts = .bsf~new("org.apache.commons.vfs2.FileSystemOptions") SftpFileSystemConfigBuilder=bsf.import("org.apache.commons.vfs2.provider.sftp.SftpFileSystemConfigBuilder") instance=SftpFileSystemConfigBuilder~getInstance instance~setStrictHostKeyChecking(opt,"no") instance~setUserDirIsRoot(opts, .true) instance~setTimeout(opts, 10000) -- Create the SFTP URI using the host name, userid, password, remote path and file name -- String sftpUri = "sftp://" + userId + ":" + password + "@" + serverAddress + "/" + sftpUri = "sftp://"userId":"password"@"serverAddress"/"remoteDirectory || fileToFTP -- Create local file object localFile = manager~resolveFile(file~getAbsolutePath) -- Create remote file object remoteFile = manager~resolveFile(sftpUri, opts) -- Copy local file to sftp server Selectors=bsf.import("org.apache.commons.vfs2.Selectors") remoteFile~copyFrom(localFile, Selectors~SELECT_SELF) say "File upload successful" manager~close return .true syntax: manager~close return .false ::requires BSF.CLS -- load Java support One can transcribe the other two Java programs to pure ooRexx as well. HTH, ---rony On 23.09.2016 12:23, Rony G. Flatscher wrote: > Hi Phillip, > > On 23.09.2016 00:00, pr gramly wrote: >> Is there something like RxFtp for sftp protocol? >> I guess, more broadly, it would be a ooRexx class to use with ssh. > AFAIK there is no such ooRexx class in existence or in the works. Whoever > implements such a > functionality for ooRexx needs to implement a security infrastructure (and > keep it up-to-date) to be > used for sftp. > > However, if you use the ooRexx package "BSF4ooRexx", then you can use Java > classes as ooRexx classes > and take advantage of any Java class (which will exploit the Java runtime > deployed Java security > infrastructure on any operating system). > > To get an idea how you can take advantage of BSF4ooRexx take a look at e.g. > the following slides: > <http://wi.wu.ac.at/rgf/wu/lehre/autojava/material/foils/AutoJava-BSF4ooRexx-03-Sockets.pdf>. > These > slides introduce newbies into socket programming using Java classes instead > of the ooRexx classes. > Then, starting with slide 23, an example is given for using ssl (which does > not exist for ooRexx) > via ooRexx (using Java classes as if they were ooRexx classes). > > BSF4ooRexx is actually quite easy and straight forward camouflaging Java > classes as ooRexx classes > and Java objects as ooRexx objects to which you merely send ooRexx messages! > The latest version is > the (stable) beta at: > <https://sourceforge.net/projects/bsf4oorexx/files/beta/20160815/>, read the > "readme" file! > > The introduction to BSF4ooRexx explaining the basic concepts can be found in > the slides > <http://wi.wu.ac.at/rgf/wu/lehre/autojava/material/foils/AutoJava-BSF4ooRexx-01.pdf>. > > > There is no need to learn programming in Java in order to use Java classes as > ooRexx classes, you > merely need to be able to read the (online) documentation of the Java APIs, > which is a set of > interconnected HTML-pages. > > If you have questions about BSF4ooRexx then just use the BSF4ooRexx mailing > lists like > <bsf4oorexx-de...@lists.sourceforge.net> or > <bsf4oorexx-supp...@lists.sourceforge.net>. > > ---rony > > P.S.: The latest BSF4ooRexx beta includes .Net support on the Windows > platform, cf. the presentation > of this year's International Rexx symposium organized by > <http://www.rexxla.org>. >
------------------------------------------------------------------------------
_______________________________________________ Oorexx-users mailing list Oorexx-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/oorexx-users