Components | All | New | MacOS | Windows | Linux | iOS | ||||
Examples | Mac & Win | Server | Client | Guides | Statistic | FMM | Blog | Deprecated | Old |
SSH.Tunnel.Run
Creates a SSH tunnel on the session.
Component | Version | macOS | Windows | Linux | Server | iOS SDK |
SSH | 8.5 | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes | ✅ Yes |
Parameters
Parameter | Description | Example |
---|---|---|
SSH | The SSH session reference number from the plugin. | $ssh |
RemoteHost | The remote host to forward to. Can be IP or domain name. |
"monkeybreadsoftware.com" |
RemotePort | The destination port to connect to. | 80 |
LocalHost | The local interface to listen on. | "127.0.0.1" |
LocalPort | The local port to listen on. | 8000 |
Result
Returns OK or error.
Description
Creates a SSH tunnel on the session.Please create, connect and authenticate a session for use as a tunnel.
For best result, please don't use the same session for other things while tunnel is running.
The tunnel allows currently one connection through it, e.g. run one tunnel per MySQL connection to go through the tunnel. If you need multiple tunnels, please create multiple SSH connections.
The MBS Plugin can spin of a new preemptive thread to run a tunnel to forward a SSH connection from local socket to remote server via SSH tunnel.
This works well e.g. for database access with MySQL.
By using our own thread, we are not blocking or blocked by your FileMaker scripts.
Examples
Run SSH Tunnel to connect to MySQL:
# some settings like local IP/Port
Set Variable [ $LocalIP ; Value: "127.0.0.1" ]
Set Variable [ $LocalPort ; Value: 3306 ]
# the SSH server to connect through
Set Variable [ $SSHServerIP ; Value: "myserver.test" ]
# database to connect
Set Variable [ $DatabaseIP ; Value: "db.myserver.test" ]
Set Variable [ $DatabasePort ; Value: 3306 ]
# create connection
Set Variable [ $ssh ; Value: MBS( "SSH.New" ) ]
Set Variable [ $r ; Value: MBS( "SSH.Connect"; $ssh; $SSHServerIP ) ]
Set Variable [ $r ; Value: MBS( "SSH.SessionHandshake"; $ssh) ]
# using private key file here, but username+password is also possible
Set Variable [ $r ; Value: MBS( "SSH.UserAuthPublicKeyFile"; $ssh; "username"; "" ; $keypair_path ; "password" ) ]
Set Variable [ $auth ; Value: MBS( "SSH.IsAuthenticated"; $ssh ) ]
# must be 1
Set Variable [ $r ; Value: MBS( "SSH.Tunnel.Run"; $ssh; $DatabaseIP; $DatabasePort; $LocalIP; $LocalPort) ]
Pause/Resume Script [ Duration (seconds): .5 ]
Set Variable [ $tunnel_mess ; Value: MBS( "SSH.Tunnel.Messages"; $ssh ) ]
# now this should show that tunnel is waiting.
Set Variable [ $Connection ; Value: MBS("SQL.NewConnection") ]
Set Variable [ $r ; Value: MBS("SQL.SetConnectionOption"; $Connection; "MYSQL.LIBS"; $mysql_path ) ]
Set Variable [ $r ; Value: MBS("SQL.SetClient"; $Connection; "MySQL") ]
Set Variable [ $r ; Value: MBS("SQL.Connect"; $Connection; $LocalIP & "," & $LocalPort & "@DatabaseName"; "UserName"; "password"; "MySQL") ]
Set Variable [ $tunnel_mess ; Value: MBS( "SSH.Tunnel.Messages"; $ssh ) ]
Show Custom Dialog [ $tunnel_mess & ¶ & $r ]
# should show OK for connect and for tunnel that it's forwarding data
# do query here
# disconnect
Set Variable [ $r ; Value: MBS("SQL.FreeConnection"; $Connection) ]
Set Variable [ $r ; Value: MBS( "SSH.Tunnel.Cancel"; $ssh ) ]
Pause/Resume Script [ Duration (seconds): .1 ]
Set Variable [ $r ; Value: MBS( "SSH.Disconnect"; $ssh ) ]
Set Variable [ $r ; Value: MBS( "SSH.Release"; $ssh ) ]
Run SSH Tunnel to connect to MongoDB:
# some settings like local IP/Port
Set Variable [ $LocalIP ; Value: "127.0.0.1" ]
Set Variable [ $LocalPort ; Value: 12345 ]
# the SSH server to connect through
Set Variable [ $SSHServerIP ; Value: "myserver.test" ]
# database to connect
Set Variable [ $DatabaseIP ; Value: "db.myserver.test" ]
Set Variable [ $DatabasePort ; Value: 27017 ]
# create connection
Set Variable [ $ssh ; Value: MBS( "SSH.New" ) ]
Set Variable [ $r ; Value: MBS( "SSH.Connect"; $ssh; $SSHServerIP ) ]
Set Variable [ $r ; Value: MBS( "SSH.SessionHandshake"; $ssh) ]
# using private key file here, but username+password is also possible
Set Variable [ $r ; Value: MBS( "SSH.UserAuthPublicKeyFile"; $ssh; "username"; "" ; $keypair_path ; "password" ) ]
Set Variable [ $auth ; Value: MBS( "SSH.IsAuthenticated"; $ssh ) ]
# must be 1
Set Variable [ $r ; Value: MBS( "SSH.Tunnel.Run"; $ssh; $DatabaseIP; $DatabasePort; $LocalIP; $LocalPort) ]
Pause/Resume Script [ Duration (seconds): .5 ]
Set Variable [ $tunnel_mess ; Value: MBS( "SSH.Tunnel.Messages"; $ssh ) ]
# now this should show that tunnel is waiting.
Set Variable [ $MongoDB ; Value: MBS("MongoDB.New") ]
Set Variable [ $r ; Value: MBS("MongoDB.SetURI"; $MongoDB; "mongodb://" & $LocalIP & ":" & $DatabasePort & "/") ]
Set Variable [ $r ; Value: MBS("MongoDB.Connect"; $MongoDB) ]
Set Variable [ $tunnel_mess ; Value: MBS( "SSH.Tunnel.Messages"; $ssh ) ]
Show Custom Dialog [ $tunnel_mess & ¶ & $r ]
# should show OK for connect and for tunnel that it's forwarding data
# do query here
Set Variable [ $list ; Value: MBS( "MongoDB.DatabasesNames"; $MongoDB ) ]
Show Custom Dialog [ "Databases" ; $list ]
# disconnect
Set Variable [ $r ; Value: MBS("SQL.Release"; $MongoDB) ]
Set Variable [ $r ; Value: MBS( "SSH.Tunnel.Cancel"; $ssh ) ]
Pause/Resume Script [ Duration (seconds): .1 ]
Set Variable [ $r ; Value: MBS( "SSH.Disconnect"; $ssh ) ]
Set Variable [ $r ; Value: MBS( "SSH.Release"; $ssh ) ]
See also
- SQL.SetClient
- SQL.SetConnectionOption
- SSH.Disconnect
- SSH.IsAuthenticated
- SSH.Release
- SSH.SessionHandshake
- SSH.Tunnel.Cancel
- SSH.Tunnel.Running
- SSH.UserAuthPublicKey
- SSH.UserAuthPublicKeyFile
Release notes
- Version 8.5
- Added SSH functions to create SSH tunnel, see SSH.Tunnel.Run.
Example Databases
Blog Entries
This function checks for a license.
Created 22nd October 2018, last changed 4th March 2023