Using gb.util prompt/expect with ssh client

Post your Gambas programming questions here.
Post Reply
User avatar
zagirovaa
Posts: 5
Joined: Tuesday 27th September 2016 5:48am

Using gb.util prompt/expect with ssh client

Post by zagirovaa » Friday 11th June 2021 8:52am

Hi, everyone!

I would like to know whether anyone had success with connecting to ssh server (or telnet) using expect/prompt from Process class that is in gb.util component (beginning with Gambas 3.15)? I myself tried but with no success. Any working example would be appriciated!

Thanks in advance!

User avatar
cogier
Site Admin
Posts: 721
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Using gb.util prompt/expect with ssh client

Post by cogier » Saturday 12th June 2021 3:50pm

Welcome to the forum.

This is a puzzle. Two of us have been trying to get this to work for the last 3 hours with very little progress. We haven't given up just yet, so watch this space. Can you tell us what you are trying to achieve, there maybe another way to do this?

User avatar
zagirovaa
Posts: 5
Joined: Tuesday 27th September 2016 5:48am

Re: Using gb.util prompt/expect with ssh client

Post by zagirovaa » Sunday 13th June 2021 12:24pm

Hi!

I would like to develop an application which would periodically save configurations of active network devices like switches, routers, etc. I could implement that using python and qt (in python there are different libraries like paramiko) but it is much more easier to develop GUI applications in Gambas than in any other language.

Looking forward to your help!

User avatar
zagirovaa
Posts: 5
Joined: Tuesday 27th September 2016 5:48am

Re: Using gb.util prompt/expect with ssh client

Post by zagirovaa » Sunday 13th June 2021 12:29pm

Please, have a look at this project: https://cbackup.me/en/
It works great for me (written in java and php) but it is no longer supported and i would like to expand the functionality it gives in my application.

User avatar
cogier
Site Admin
Posts: 721
Joined: Wednesday 21st September 2016 2:22pm
Location: Guernsey, Channel Islands

Re: Using gb.util prompt/expect with ssh client

Post by cogier » Sunday 13th June 2021 2:22pm

This is going over my head. However, if you can do all this in Java and PHP then why not use that code and pull it in to Gambas to display.

Here is a Gambas program in which I created some simple Python, ran the Python and displayed the result in Gambas.
TestNew-0.0.11.tar.gz
(12.21 KiB) Downloaded 1 time

User avatar
BruceSteers
Posts: 521
Joined: Thursday 23rd July 2020 5:20pm

Re: Using gb.util prompt/expect with ssh client

Post by BruceSteers » Sunday 13th June 2021 4:47pm

Maybe ask on the gambas mailing list?
I read in the wiki the bit from Process.Expect()
http://gambaswiki.org/wiki/comp/gb.util/process/expect

Read some bit (cannot remember where) that said no more but had (Think ssh/ssl) appended to it.
but it had no further explanation/example.

I'd try the mailing list and see if whoever wrote the command has an explanation.

Does this not help?...
Dim hProcess As Process
Dim sPassword As String = "BigSecret"
  
hProcess = Shell "scp /all/that/stuff/* login@server:~/here" For Input Output As "Process"
' Handle the message emitted when the server is unknown
hProcess.Expect("(yes/no*)?", "yes")
' Any emitted string ending with a colon is supposed to be the password prompt
hProcess.Expect(":", sPassword)
' Wait for the process to terminate
hProcess.Wait
Wishing well
Bruce

If at first you don't succeed , try it differently.

User avatar
zagirovaa
Posts: 5
Joined: Tuesday 27th September 2016 5:48am

Re: Using gb.util prompt/expect with ssh client

Post by zagirovaa » Sunday 13th June 2021 5:12pm

cogier wrote:
Sunday 13th June 2021 2:22pm
This is going over my head. However, if you can do all this in Java and PHP then why not use that code and pull it in to Gambas to display.

Here is a Gambas program in which I created some simple Python, ran the Python and displayed the result in Gambas.

TestNew-0.0.11.tar.gz
Hi!

I didn't say that I know Java or Php. I meant that CBackup project is written in those languages. I gave you the link to the project as an example what I would like to implement. And I would like to write the whole code in pure gambas. According to Gambas wiki there is an appropriate functionality but, unfortunately, it doesn't work as I expect it to.

User avatar
zagirovaa
Posts: 5
Joined: Tuesday 27th September 2016 5:48am

Re: Using gb.util prompt/expect with ssh client

Post by zagirovaa » Sunday 13th June 2021 5:15pm

BruceSteers wrote:
Sunday 13th June 2021 4:47pm
Maybe ask on the gambas mailing list?
I read in the wiki the bit from Process.Expect()
http://gambaswiki.org/wiki/comp/gb.util/process/expect

Read some bit (cannot remember where) that said no more but had (Think ssh/ssl) appended to it.
but it had no further explanation/example.

I'd try the mailing list and see if whoever wrote the command has an explanation.

Does this not help?...
Dim hProcess As Process
Dim sPassword As String = "BigSecret"
  
hProcess = Shell "scp /all/that/stuff/* login@server:~/here" For Input Output As "Process"
' Handle the message emitted when the server is unknown
hProcess.Expect("(yes/no*)?", "yes")
' Any emitted string ending with a colon is supposed to be the password prompt
hProcess.Expect(":", sPassword)
' Wait for the process to terminate
hProcess.Wait
I already read everything related to expect/prompt on Gambas wiki but that doesn't work when it comes to ssh and/or telnet. I asked the same question in Gambas official IRC channel. No answer. I will try mailing list as you advised.

Post Reply