How to use tftpy - 10 common examples

To help you get started, we’ve selected a few tftpy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alliedtelesis / py-networking / tests / test_license.py View on Github external
dut.tftp_port = 69
        if (getpass.getuser() != 'root'):
            dut.tftp_port = 20069

        client_dir = './tftp_client_dir'
        server_dir = './tftp_server_dir'
        if (os.path.exists(client_dir) == False):
            os.mkdir(client_dir)
        if (os.path.exists(server_dir) == False):
            os.mkdir(server_dir)
        if not hasattr(dut, 'tftp_server_thread'):
            dut.tftp_server_thread = threading.Thread(target=tftp_server_for_ever, args=(dut.tftp_port, server_dir,))
            dut.tftp_server_thread.daemon = True
            dut.tftp_server_thread.start()

        tftp_client = tftpy.TftpClient(socket.gethostbyname(socket.getfqdn()), dut.tftp_port)
        tftp_client.upload(cert_file.split('/')[-1], cert_file)
github alliedtelesis / py-networking / tests / test_file_ats.py View on Github external
def tftp_server_for_ever(port, tftp_server_dir):
    ip_address = socket.gethostbyname(socket.getfqdn())
    server = tftpy.TftpServer(tftp_server_dir)
    server.listen(ip_address, port)
github alliedtelesis / py-networking / tests / test_license.py View on Github external
def tftp_server_for_ever(port, tftp_server_dir):
    ip_address = socket.gethostbyname(socket.getfqdn())
    server = tftpy.TftpServer(tftp_server_dir)
    server.listen(ip_address, port)
github ovn-org / ovn / tests / test-l7.py View on Github external
def __init__(self, listen, handler=None):
                (ip, port) = listen
                self.ip = ip
                self.port = port
                TftpServer.__init__(self, tftproot='./')
github alliedtelesis / py-networking / tests / test_device_ats.py View on Github external
def tftp_server_for_ever(port, tftp_server_dir):
    ip_address = socket.gethostbyname(socket.getfqdn())
    server = tftpy.TftpServer(tftp_server_dir)
    # log_level = logging.DEBUG
    log_level = logging.WARNING
    log = logging.getLogger('tftpy')
    log.setLevel(log_level)
    server.listen(ip_address, port, timeout=20)
github dhtech / swboot / swtftpd.py View on Github external
f = tempfile.TemporaryFile()
  if file_to_transfer.lower().endswith("-confg"):
    log("Generating config for", raddress,"config =", switch)
    if generate(f, raddress, switch) == None:
      return None
  else:
    error("Switch", raddress, "config =", switch, "tried to get file",
        file_to_transfer)
    f.close()
    return None

  f.seek(0)
  return f

log("swtftpd started")
server = tftpy.TftpServer('/srv/tftp', file_callback)
tftplog = logging.getLogger('tftpy.TftpClient')
tftplog.setLevel(logging.WARN)
try:
  server.listen("192.168.40.10", 69)
except tftpy.TftpException as err:
  sys.stderr.write("%s\n" % str(err))
  sys.exit(1)
except KeyboardInterrupt:
  sys.stderr.write("\n")
github msoulier / tftpy / bin / tftpy_server.py View on Github external
help='upgrade logging from info to debug')
    options, args = parser.parse_args()

    if options.debug:
        log.setLevel(logging.DEBUG)
        # increase the verbosity of the formatter
        debug_formatter = logging.Formatter('[%(asctime)s%(msecs)03d] %(levelname)s [%(name)s:%(lineno)s] %(message)s')
        handler.setFormatter(debug_formatter)
    elif options.quiet:
        log.setLevel(logging.WARN)

    if not options.root:
        parser.print_help()
        sys.exit(1)

    server = tftpy.TftpServer(options.root)
    try:
        server.listen(options.ip, options.port)
    except tftpy.TftpException as err:
        sys.stderr.write("%s\n" % str(err))
        sys.exit(1)
    except KeyboardInterrupt:
        pass
github alliedtelesis / py-networking / pynetworking / features / ats_file.py View on Github external
if (filename == ''):
            filename = name
            myfile = open(filename, 'w')

            # TFTP doesn't allow empty file creation
            if (text == ''):
                myfile.write('\n')
            else:
                myfile.write(text)
            myfile.close()

        # upload on TFTP server
        if (server == ''):
            server = socket.gethostbyname(socket.getfqdn())
        tftp_client = tftpy.TftpClient(server, port)
        tftp_client.upload(filename.split('/')[-1], filename)
        self._tftp_port = port

        # device commands (timeout of 60 seconds for each MB)
        timeout = (os.path.getsize(filename) / 1048576 + 1) * 60000
        create_cmd = 'copy {0}://{1}/{2} {3}'.format(protocol, server, filename.split('/')[-1], name)
        cmds = {'cmds': [{'cmd': create_cmd, 'prompt': '\#', 'timeout': timeout}]}
        self._device.cmd(cmds, cache=False, flush_cache=True)
        self._update_file()
github Phype / telnet-iot-honeypot / sampledb.py View on Github external
m = r.match(url)
		if m:
			host  = m.group(1)
			port  = m.group(2)
			fname = m.group(3)
			
			if port == "":
				port = 69
			
			f = {}
			f["name"] = url.split("/")[-1].strip()
			f["date"] = int(time.time())
			f["len"]  = 0
			f["file"] = self.dir + str(f["date"]) + "_" + f["name"]
			
			client = tftpy.TftpClient(host, int(port))
			client.download(fname, f["file"])
			
			h = hashlib.sha256()
			with open(f["file"], 'rb') as fd:
				chunk = fd.read(4096)
				h.update(chunk)
			
			f["sha256"] = h.hexdigest()
			
			return f
		else:
			raise ValueError("Invalid tftp url")
github msoulier / tftpy / bin / tftpy_client.py View on Github external
tftp_options,
                               options.localip)
    try:
        if options.download:
            if not options.output:
                options.output = os.path.basename(options.download)
            tclient.download(options.download,
                             options.output,
                             progresshook)
        elif options.upload:
            if not options.input:
                options.input = os.path.basename(options.upload)
            tclient.upload(options.upload,
                           options.input,
                           progresshook)
    except tftpy.TftpException as err:
        sys.stderr.write("%s\n" % str(err))
        sys.exit(1)
    except KeyboardInterrupt:
        pass