PowerBuilder
PowerBuilder
Check Whether SSH Channel EOF Was Received
See more SSH Examples
Demonstrates the Chilkat Ssh.ChannelReceivedEof method, which reports whether an SSH EOF message has been received for a channel. The only argument is the channel number. EOF means the server will send no more ordinary channel data, but it does not close the channel.
Background: EOF and CLOSE are separate events, and the distinction matters when deciding whether a command has truly finished. A server commonly sends EOF first and CLOSE afterward; in that interval this method is true while
ChannelReceivedClose is still false, and the channel remains open and counted. EOF is the signal that all output has been produced — useful when you want to stop reading without waiting for the full close handshake. It returns false for an invalid, released, or locally closed channel.Chilkat PowerBuilder Downloads
integer li_rc
integer li_Success
oleobject loo_Ssh
integer li_SshPort
string ls_Password
integer li_ChannelNum
li_Success = 0
// Demonstrates the Ssh.ChannelReceivedEof method, which reports whether an SSH EOF message has
// been received for a channel. The only argument is the channel number. EOF means the server
// will send no more ordinary channel data, but it does not close the channel.
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
li_ChannelNum = loo_Ssh.OpenSessionChannel()
if li_ChannelNum < 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
li_Success = loo_Ssh.SendReqExec(li_ChannelNum,"ls -l /tmp")
if li_Success = 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
// IMPORTANT: Set a read timeout. ReadTimeoutMs defaults to 0, which means no limit -- without
// it, this call waits forever if the server never sends channel close.
loo_Ssh.ReadTimeoutMs = 15000
li_Success = loo_Ssh.ChannelReceiveToClose(li_ChannelNum)
if li_Success = 0 then
Write-Debug loo_Ssh.LastErrorText
destroy loo_Ssh
return
end if
if loo_Ssh.ChannelReceivedEof(li_ChannelNum) then
Write-Debug "EOF was received -- no more ordinary channel data will arrive."
else
Write-Debug "No EOF has been received."
end if
loo_Ssh.Disconnect()
destroy loo_Ssh