PowerBuilder
PowerBuilder
Request SSH X11 Forwarding
See more SSH Examples
Demonstrates the Chilkat Ssh.SendReqX11Forwarding method, which sends an X11-forwarding request on a session channel. The arguments are the channel number, whether forwarding is limited to a single connection, and the X11 authentication protocol, cookie, and screen number.
Background: X11 forwarding lets a graphical program running on the remote host display its window on your local machine, tunneled over SSH. This is a low-level method that only sends the protocol request — your application is still responsible for the local X server side of the arrangement. The authentication cookie guards the forwarded display, so it should be a freshly generated value rather than a fixed constant.
Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Ssh
integer li_SshPort
string ls_Password
integer li_ChannelNum
integer li_SingleConnection
string ls_AuthProt
string ls_AuthCookie
integer li_ScreenNum
li_Success = 0
// Demonstrates the Ssh.SendReqX11Forwarding method, which sends an SSH X11-forwarding request
// on a session channel. The 1st argument is the channel number, the 2nd limits forwarding to a
// single connection, and the 3rd through 5th supply the X11 authentication protocol, cookie,
// and screen number.
loo_Ssh = create oleobject
li_rc = loo_Ssh.ConnectToNewObject("Chilkat.Ssh")
if li_rc < 0 then
destroy loo_Ssh
MessageBox("Error","Connecting to COM object failed")
return
end if
li_SshPort = 22
li_Success = loo_Ssh.Connect("ssh.example.com",li_SshPort)
if li_Success = 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
// Normally you would not hard-code the password in source. You should instead obtain it
// from an interactive prompt, environment variable, or a secrets vault.
ls_Password = "mySshPassword"
li_Success = loo_Ssh.AuthenticatePw("mySshLogin",ls_Password)
if li_Success = 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
// Open a session channel. A negative return value indicates failure.
li_ChannelNum = loo_Ssh.OpenSessionChannel()
if li_ChannelNum < 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
// Request X11 forwarding. Named variables make each argument's meaning clear.
li_SingleConnection = 0
ls_AuthProt = "MIT-MAGIC-COOKIE-1"
ls_AuthCookie = "d92f5e1a7c8b4306af17c2e5b9d43081"
li_ScreenNum = 0
li_Success = loo_Ssh.SendReqX11Forwarding(li_ChannelNum,li_SingleConnection,ls_AuthProt,ls_AuthCookie,li_ScreenNum)
if li_Success = 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
Write-Debug "X11 forwarding requested."
loo_Ssh.Disconnect()
destroy loo_Ssh