#! /usr/bin/python import telnetlib, os, time, datetime username = "utente" password = "passwordutente" passwordena = "passwordena" router = "192.168.1.213" srvbckp = "192.168.1.198" ios1700 = "c1700-ipbase-mz.124-1c.bin" tn = telnetlib.Telnet(router) tn.read_until("Username: ") tn.write(username + "\r\n") if password: tn.read_until("Password: ") tn.write(password + "\r\n") tn.write("terminal length 0" + "\r\n") tn.write("en"+ "\r\n") tn.read_until("Password: ") tn.write(passwordena + "\r\n") tn.write("copy flash tftp" + "\r\n") tn.read_until("Source filename []? ") tn.write(ios1700 + "\r\n") tn.read_until("Address or name of remote host []?") tn.write(srvbckp + "\r\n") tn.read_until("Destination filename [c1700-ipbase-mz.124-1c.bin]?") tn.write("\r\n") tn.write("q"+ "\r\n") log = tn.read_all() tn.close() #time.sleep(100) os.rename("c1700-ipbase-mz.124-1c.bin", "c1700-ipbase-mz.124-1c.bin_" + time.strftime('%d%m%Y%H%M%S')) print log