How to use the tftpy.TftpServer function in tftpy

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_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 PackeTsar / freeztp / ztp.py View on Github external
def start_tftp():
	tftpy.setLogLevel(logging.DEBUG)
	server = tftpy.TftpServer("/", dyn_file_func=interceptor)
	server.listen(listenip="", listenport=69)
github PackeTsar / freeztp / ztp.py View on Github external
global tftpy
	import tftpy
	try:
		tftpy.TftpContextServer.start = start  # Overwrite the function
		tftpy.TftpContextServer.end = end  # Overwrite the function
		tftpy.TftpStateExpectACK.sendDAT = sendDAT
	except NameError:
		pass
	log("start_tftp: Starting Up TFTPy")
	#tftpy.setLogLevel(logging.DEBUG)
	try:
		server = tftpy.TftpServer(config.running["tftproot"], dyn_file_func=interceptor)
	except tftpy.TftpShared.TftpException:
		log("start_tftp: ERROR: TFTP Root path doesn't exist. Creating...")
		os.system('mkdir -p ' + config.running["tftproot"])
		server = tftpy.TftpServer(config.running["tftproot"], dyn_file_func=interceptor)
	server.listen(listenip="", listenport=69)
	log("start_tftp: Started up successfully")
github agreenbhm / GhittoPCM / GhittoPCM.py View on Github external
def startTftpServer(tftpRoot):
	#create TFTP server using defined directory for target
	global globalError
	global tftpServer
		
	if not os.path.exists(tftpRoot):
		os.makedirs(tftpRoot)
	
	try:
		tftpServer = tftpy.TftpServer(tftpRoot)
		tftpServer.listen('0.0.0.0', 69)
	
	except Exception, e:
		print "\nError starting TFTP server (maybe another instance is running?)"
		print "\nError message is: " + str(e)
		globalError = True