Suppose you want to send a file from modem A to modem B. Ensure that you enable the remote functionality on destination modem B by using the command remote.enable=true
. Once remote is enabled, you can utilize the Python class below to initiate the file transfer between the two modems.
from unetpy import *
import time
class SendFile:
def __init__(self, sock, recipient, file, number_of_loops=1, sleep_between_loops=0):
self.sock = sock
try:
self.file = file
self.recipient = recipient
self.number_of_loops = number_of_loops
self.sleep_between_loops = sleep_between_loops
except Exception as ex:
print("\033[91m-E- failed to load signal file\033[0m")
print(str(ex))
exit()
def id(self):
print()
print("\033[92m------------------------------------------------------\033[0m")
print("\033[92mTask Type: SendFile\033[0m")
print("\033[92mRecipient: {}\033[0m".format(self.recipient))
print("\033[92mSending File: {}\033[0m".format(self.file))
print("\033[92mNumber_of_loops: {}\033[0m".format(self.number_of_loops))
print("\033[92mSleep_between_loops: {}\033[0m".format(self.sleep_between_loops))
def exec_step(self):
print()
gw = self.sock.getGateway()
remote = gw.agentForService(Services.REMOTE)
remote.enable = True
for i in range(0, self.number_of_loops):
print()
print("\033[94m-I- Sending a File remotely #{} {}\033[0m".format(i + 1, self.file))
remote << RemoteFilePutReq(to=self.recipient, filename=self.file)
if self.sleep_between_loops:
print("\033[94m-I- Sleeping for {} seconds\033[0m".format(self.sleep_between_loops))
time.sleep(self.sleep_between_loops)
print("\033[92m------------------------------------------------------\033[0m")
if __name__ == "__main__":
sock = UnetSocket("localhost", 1101)
task = SendFile(sock, 31, "README.md")
task.id()
task.exec_step()
You can check the logs on remote by enabling subscribe remote
.