GvmError: Remove closed the connection

I am trying to run a simple script using the python-gvm library from a windows machine to connect to my Breenbone Security Manager on another machine.
The script goes like this:

from gvm.connections import SSHConnection
from gvm.protocols.gmp import Gmp
from gvm.transforms import EtreeTransform

connection = SSHConnection(hostname=<HOSTNAME>, username=<ADMIN>, password=<PASSWORD>)
transform = EtreeTransform()

with Gmp(connection, transform=transform) as gmp:
    # Retrieve GMP version supported by the remote daemon
    version = gmp.get_version()

But I keep getting the same error, which I can’t understand why is popping up:

GvmError                                  Traceback (most recent call last)
<ipython-input-21-1e67790e5056> in <module>
----> 1 with Gmp(connection=connection) as gmp:
      2     pretty_print(gmp.get_version())

c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\gvm\protocols\gmp.py in __enter__(self)
    123     def __enter__(self):
--> 124         gmp = self.determine_supported_gmp()
    126         gmp.connect()

c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\gvm\protocols\gmp.py in determine_supported_gmp(self)
    101         corresponding Gmp class instance
    102         """
--> 103         version = self.determine_remote_gmp_version()
    104         major_version = int(version.split('.')[0])
    105         if major_version == 7:

c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\gvm\protocols\gmp.py in determine_remote_gmp_version(self)
     85         """Determine the supported GMP version of the remote daemon"""
     86         self.connect()
---> 87         resp = self._send_xml_command(XmlCommand("get_version"))
     88         self.disconnect()

c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\gvm\protocols\base.py in _send_xml_command(self, xmlcmd)
     84             xmlcmd (gvm.xml.XmlCommand): XmlCommand instance to send
     85         """
---> 86         return self.send_command(xmlcmd.to_string())
     88     def is_connected(self) -> bool:

c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\gvm\protocols\base.py in send_command(self, cmd)
    138         except Exception as e:
    139             self.disconnect()
--> 140             raise e
    142         return self._transform(response)

c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\gvm\protocols\base.py in send_command(self, cmd)
    135         try:
    136             self._send(cmd)
--> 137             response = self._read()
    138         except Exception as e:
    139             self.disconnect()

c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\gvm\protocols\base.py in _read(self)
     61             str: Response from server.
     62         """
---> 63         return self._connection.read()
     65     def _send(self, data):

c:\users\user\appdata\local\programs\python\python38-32\lib\site-packages\gvm\connections.py in read(self)
    139             if not data:
    140                 # Connection was closed by server
--> 141                 raise GvmError("Remote closed the connection")
    143             self._feed_xml(data)

GvmError: Remote closed the connection

What could cause this issue?

GVM versions

Wasn’t sure to which each of those fields refer to, but the version of python-gvm I downloaded from pip was 21.1.3 and the version of the Greenbone OS is 20.08.7
I hope this is OK.


The Environment that runs the script is a windows 10 and the Greenbone Security Manager runs on a Greenbone OS 20.08.7

Hi, it would be easier to use a gmp script and run it via gvm-tools. gvm-tools already provides and implements the correct connection handling. If you have a GSM just use the defaults to create the SSHConnection. Don’t pass any parameters to the constructor of that class besides the hostname.

1 Like

I gave it a shot, writing the following script:

def main(gmp, args):
    version = gmp.get_version()

if __name__ == '__gmp__':
    main(gmp, args) 

and then running:
gvm-script ssh --hostname C:\Users\user\AppData\Roaming\JetBrains\PyCharmCE2020.2\scratches\greenbone.py

But what I get is:
SSH Connection failed

Did you activate GMP in the GOS menu?


The SSH access is not available in the GSM Trial.

1 Like

I see, I am using the GSM Trial, if so, is there another way to send automated commands to the GSM in the free trial?

No. You can only run GMP scripts on the GSM Trial directly.

1 Like