Search code examples
pythonpython-3.xunetstack

Uploading files to acoustical modem


I'm trying to send files between two acoustical modems from subnero (WNC-M25MSS4). I have developed a python script which uses fjagepy library to execute the unetstack command: fput node address , 'file':

import sys
from fjagepy import Gateway, MessageClass

if len(sys.argv) != 6:
    print("Usage: python3 ac_sender.py <source_ip_address> <port> <destination_address> <timeout(ms)><filename>")
    sys.exit(1)

ip_address = sys.argv[1]
port = int(sys.argv[2])
node = int(sys.argv[3])
timeout = int(sys.argv[4])
file_name = sys.argv[5]

gw = Gateway(ip_address, port)
ShellExecReq = MessageClass('org.arl.fjage.shell.ShellExecReq')
shell = gw.agentForService('org.arl.fjage.shell.Services.SHELL')

cmd = "fput {}, '{}'".format(node, file_name)
req = ShellExecReq(recipient=shell, cmd=cmd)

rsp = gw.request(req, timeout)
print(rsp)

gw.close()`


I'm thinking of using unetstack's Python API (unetpy) to remotely upload files to an acoustic modem. However, I don't quite understand how to do this.

How can i upload files to modem without uploading through Unetstack UI?


Solution

  • I was finally able to upload files to the acoustical modem.

    To do this just request the shell agent to put a file in a specific path using the putfilereq message type:

    gw = Gateway(ip_address, port)
    PutFileReq = MessageClass('org.arl.fjage.shell.PutFileReq')
    shell = gw.agentForService('org.arl.fjage.shell.Services.SHELL')
    
    with open(file_name, 'rb') as file:
        contents = file.read()
        encoded_contents = base64.b64encode(contents).decode('utf-8')
    
    req = PutFileReq(recipient=shell, filename=remote_file_name, contents=encoded_contents)
    rsp = gw.request(req, timeout)