Ejemplo n.º 1
0
    def put_file(self, src, dest):
        """Uploads a file to the tftp server.

        .. note::
            * TftpClient is not threadsafe, so we create a unique instance for
              each transfer.

        >>> e_tftp.put_file(src='local_file.txt', dest='remote_name.txt')

        :param src: Source file path (on your local machine).
        :type src: string
        :param dest: Destination path (on the TFTP server).
        :type dest: string

        :raises TftpException: If the file cannot be written to the TFTP server.
        :raises TftpException: If a TypeError is received from tftpy.

        """
        try:
            client = TftpClient(self.ip_address, self.port)
            client.upload(input=src, filename=dest)
        except TftpException:
            if (self.verbose):
                traceback.format_exc()
            raise
        except TypeError:
            if (self.verbose):
                traceback.format_exc()
            raise TftpException("Failed to upload file to TFTP server")
Ejemplo n.º 2
0
    def download(self, host, port, fname):
        output = DummyIO()
        client = TftpClient(host, port)

        self.env.write("Trying " + host + ":" + str(port) + " ... ")
        client.download(fname, output, timeout=5, packethook=self.pkt)
        return output.data
Ejemplo n.º 3
0
    def get_file(self, src, dest):
        """Download a file from the ExternalTftp Server.

        .. note::
            * TftpClient is not threadsafe, so we create a unique instance for
              each transfer.

        >>> e_tftp.get_file(src='remote_file_i_want.txt', dest='/local/path')

        :param src: The path to the file on the Tftp server.
        :type src: string
        :param dest: The local destination to copy the file to.
        :type dest: string

        :raises TftpException: If the file does not exist or cannot be obtained
                               from the TFTP server.
        :raises TftpException: If a TypeError is received from tftpy.

        """
        try:
            client = TftpClient(self.ip_address, self.port)
            client.download(output=dest, filename=src)
        except TftpException:
            if (self.verbose):
                traceback.format_exc()
            raise
        except TypeError:
            if (self.verbose):
                traceback.format_exc()
            raise TftpException("Failed download file from TFTP server")
Ejemplo n.º 4
0
    def download(self, host, port, fname):
        if config.get("fake_dl", optional=True, default=False):
            return str(hash(host + str(port) + fname))

        output = DummyIO()
        client = TftpClient(host, port)

        self.env.write("Trying " + host + ":" + str(port) + " ... ")
        client.download(fname, output, timeout=5, packethook=self.pkt)
        return output.data
Ejemplo n.º 5
0
    def setUp(self):
        conpot_core.initialize_vfs()

        self.tftp_server, self.greenlet = spawn_test_server(TftpServer,
                                                            template="default",
                                                            protocol="tftp")

        self.client = TftpClient(self.tftp_server.server.server_host,
                                 self.tftp_server.server.server_port)
        self._test_file = "/".join(conpot.__path__ +
                                   ["tests/data/test_data_fs/tftp/test.txt"])
Ejemplo n.º 6
0
def checkTFTP(url, port, block = '512'):
    response = {}
    try:
        tftp_options = {}
        tftp_options['blksize'] = int(block)
        b = time()
        cliente = TftpClient(url, int(port), tftp_options)
        a = time() - b
        response['Tiempo Conexion (s)'] = a
        b = time()
        cliente.download(file, file)
        a = time() - b
        response['Tiempo Descarga (s)'] = a
        b = time()
        cliente.upload(file, file)
        a = time() - b
        response['Tiempo Carga (s)'] = a
        response['status'] = 'Up'
    except:
        response['status'] = 'Down'

    return response
Ejemplo n.º 7
0
    def verify_server(self):
        ip = self.server_info['address']
        port = self.server_info['port']
        path = self.server_info['path']

        # Set up client logging
        logfile = self.server_info.get('logfile', None)
        if logfile:
            logfile = '%s.client%s' % os.path.splitext(logfile)
            ftp_logger = logging.getLogger('tftpy')
            ftp_logger.setLevel(logging.DEBUG)
            ftp_logger.propagate = False
            ftp_handler = logging.FileHandler(logfile)
            ftp_logger.addHandler(ftp_handler)

        # Create a temporary file to copy to the TFTP server
        with tempfile.TemporaryDirectory() as tmpdir:
            # Create a file that will not conflict with any existing files
            filename = self._generate_filename()
            filepath = os.path.join(tmpdir, filename)
            with open(filepath, 'w') as f:
                f.write('ab' * 100)

            # can't write to root. Use tmpdir instead
            if path == '/':
                filename = os.path.join(tmpdir, '%s2' % filename)

            client = TftpClient(ip, port)
            client.upload(filename, filepath)

            # Confirm file was copied
            upfilepath = os.path.join(path, filename)
            if not os.path.isfile(upfilepath):
                raise OSError('TFTP Upload unsuccessful')

            os.remove(upfilepath)
Ejemplo n.º 8
0
 def __init__(self,
              host_ip=socket.gethostbyname(socket.gethostname()),
              port=DEFAULT_PORT):
     self.client = TftpClient(host_ip, port)
     self.files = []
     self.file_search = glob.glob