S_trangely S_ilent H_ere

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

S_trangely S_ilent H_ere

Jason Martin
/*
 * NetRexx SSH example:
 *
 *  You will need to install the Jar file from:
 *
 *
 *    or from your software/package manager
 *
 * Arg0 = filename of known_hosts file
 * Arg1 = username of account on remote system
 * Arg2 = hostname or IP of remote system
 * Arg3 = port to use
 * Arg4 = password for above username
 * Arg5 = connectTimeout
 * Arg6 = command to send to remote system
 *
 * Example Usage after NetRexx Compile:
 *
 * java Sample '/home/user/.ssh/known_hosts' 'user' '127.0.0.1' '22' 'passwd' '60000' 'ls'
 *
 */

import com.jcraft.jsch.

class Sample

method main(argwords=String[]) static

Instance_of_JSch = JSch()

filename = String argwords[0]

username = String argwords[1]

host = String argwords[2]

port = int argwords[3]

password = String argwords[4]

connectTimeout = int argwords[5]

Instance_of_Session = Session

command = String argwords[6]

/* WARNING this is UNSECURE. UNCOMMENT only for TROUBLE SHOOTING */
--Instance_of_JSch.setConfig("StrictHostKeyChecking", "no")

do
Instance_of_JSch.setKnownHosts(filename)
catch  ex=JSchException
say ex.getMessage()
end

do
Instance_of_Session = Instance_of_JSch.getSession(username, host, port)
Instance_of_Session.setPassword(password)
Instance_of_Session.connect(connectTimeout)
catch  ex=JSchException
say ex.getMessage()
end

sb = StringBuilder()

do
channel = Instance_of_Session.openChannel("exec")
(ChannelExec channel).setCommand(command)
stream = channel.getInputStream()
channel.connect()
data = stream.read()
loop while data \== -1
sb.append(Rexx(data).d2c)
data = stream.read()
end
channel.disconnect()
catch  e=IOException
say e.getMessage()
catch  ex=JSchException
say ex.getMessage()
end

say sb.toString()

Instance_of_Session.disconnect()


_______________________________________________
Ibm-netrexx mailing list
[hidden email]
Online Archive : http://ibm-netrexx.215625.n3.nabble.com/

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: S_trangely S_ilent H_ere

gpatrick
This post has NOT been accepted by the mailing list yet.
I'm getting this error.

# nrc Sample.nrx
NetRexx portable processor 4.00-PRE build 1-20160419-0640
Copyright (c) RexxLA, 2011,2015.   All rights reserved.
Parts Copyright (c) IBM Corporation, 1995,2008.
Program Sample.nrx
  === class Sample ===
    function main(String[])
 65 +++     sb.append(Rexx(data).d2c)
    +++        ^^^^^^
    +++ Error: More than one method matches the name and signature 'java.lang.StringBuilder.append(netrexx.lang.Rexx)'
Compilation of 'Sample.nrx' failed [one error]
Loading...