'''
import telnetlib
def telnet(host, username, passwd, finish = '>'):
tn = telnetlib.Telnet(host)
tn.read_until('login: ')
tn.write(username.encode('ascii') + '\r\n'.encode('ascii'))
tn.read_until('password:')
tn.write(passwd.encode('ascii') + '\r\n'.encode('ascii'))
tn.read_until(finish)
print 'Connection succeeded!'
return tn
def closetn(tn):
tn.close() # tn.write('exit\n')
print 'The connection is closed!'
def cmdcopy(tn, sdir, ddir):
cmdcopy = r'xcopy /ey %s %s' %(sdir, ddir)
tn.write(cmdcopy.encode('ascii') + ' \r\n'.encode('ascii') )
tn.read_until(finish)
print 'File copy successful!'
if name == '__main__':
host = ''
username = 'administrator'
passwd = ' '
finish = '>'
sdir = r'D:\syncfile'
ddir = r'D:\in'
tn = telnet(host, username, passwd, finish)
cmdcopy(tn, sdir, ddir)
closetn(tn)