selfuryon / netdev

Asynchronous multi-vendor library for interacting with network devices
http://netdev.readthedocs.io/
Apache License 2.0
213 stars 44 forks source link

Are FTP transfers possible? #13

Closed ajwillo closed 6 years ago

ajwillo commented 6 years ago

Is it possible to download an IOS for example from an ftp server using netdev? ive tried with the below

        try:
            async with netdev.create(**conn[0], timeout=5) as ios:
                print('starting process on device {}.'.format(router_hostname))
                upload_ios = await ios.send_command('copy ftp://user:password@10.10.10.10/test.txt flash:')
        except:
            error = 'unable to connect to {} - {}'.format(conn[0]['host'], router_hostname)
            print(error)
            results.append(error)   

debugging gives the below output

INFO:netdev:Host 10.10.10.10: Reading until prompt or pattern
INFO:netdev:Host 10.10.10.10: Disconnecting
INFO:netdev:Host 10.10.10.10: Cleanup session
INFO:netdev:Host 10.10.10.10: Exiting from configuration mode
INFO:netdev:Host 10.10.10.10: Checking configuration mode
INFO:netdev:Host 10.10.10.10: Reading until pattern
DEBUG:netdev:Host 10.10.10.10: Reading pattern: LAB\-01\-R.*?(\(.*?\))?[\>|\#]
unable to connect to 10.10.10.10 - LAB 01

im guessing at this stage its not possible? Thanks

selfuryon commented 6 years ago

Hello! Yes, it's possible! In your example may be a problem in an interactive command copy ftp. Do you have file prompt quiet applied? Can you post the output of this command from ssh?

selfuryon commented 6 years ago

Without file prompt quiet it seems to be like that:

TEST#copy ftp://user:password@10.10.10.10/test.txt flash:
Destination filename [test.txt]? <---- Ask you for filename
Accessing ftp://*****:*****@10.10.10.10/test.txt...

So you need to use interactive command like that:

out = await ios.send_command(copy_cmd, pattern=r'Destination filename', strip_command=False)
out += await ios.send_command(filename, strip_command=False)

Or more simple solution - enable file prompt quiet before copying any files :)

ajwillo commented 6 years ago

Thanks that works!