Using Caché Internet Utilities
Using SSH
[Back] [Next]
Go to:

The %Net.SSH package provides support for SSH (Secure Shell) communications. This chapter briefly introduces the classes in this package.

Creating an SSH Session
%Net.SSH.Session represents an SSH session. To use this class:
  1. Create an instance of the class.
  2. Use the Connect() instance method to connect to a server.
  3. Use either AuthenticateWithKeyPair() or AuthenticateWithUsername() to authenticate yourself to the server. For details, see the class reference for %Net.SSH.Session.
  4. Use additional methods of %Net.SSH.Session to perform SCP (Secure Copy) operations of single files to and from the remote system, execute remote commands, tunnel TCP traffic, or perform SFTP operations. See the class reference for %Net.SSH.Session.
    For example, use OpenSFTP to use the session for SFTP operations. This method returns, by reference, an instance of %Net.SSH.SFTP that you can use for SFTP operations. See the example in the next section.
For information on the supported platforms where you can use these classes, see the class reference for %Net.SSH.Session and %Net.SSH.SFTP.
Example: Transferring Files via SFTP
The following method shows how you can get a list of the files on a server, via SFTP:
Method SFTPDir(ftpserver, username, password) As %Status
    set ssh = ##class(%Net.SSH.Session).%New()
    do ssh.Connect(ftpserver)
    do ssh.AuthenticateWithUsername(username,password)
    do ssh.OpenSFTP(.sftp)
    do sftp.Dir(".",.files)
    set i=0
    while $data(files(i))
        write $listget(files(i),1),!
        set i=i+1
    quit $$$OK
Additional Examples
For additional SSH examples, open %Net.SSH.Session in Studio and see the TestExecute() and TestForwardPort) methods of this class.