1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
#!/usr/bin/python
# recursively copy a remote directory into a local directory.
# requires that the remote site support `uuencode -m'
# Usage:
# telnet-cat.py <server> <login> <passwd> <remote-file/dir> <local-dir>
import sys, time, binascii, string
from expect import *
f = popen ("telnet %s" % (sys.argv[1],), "p")
f.read ("ogin:")
f.write (sys.argv[2] + "\n")
f.read ("word:")
time.sleep (0.1)
f.write (sys.argv[3] + "\n")
# possible prompts
f.read (("#", "$", ">"))
x = sys.argv[4]
while x[-1] == '/':
x = x[:-1]
x = string.split (x, "/")
f.write ("cd /%s && tar -cpf - %s | uuencode -m %s\n" % (string.join (x[:-1], "/"), x[-1], sys.argv[4]))
while 1:
l = f.read ('\n')
if l[:6] == "begin-":
break
g = popen ("cd %s && tar -xpf -" % (sys.argv[5]))
while 1:
l = f.read ('\n')
if l[:4] == "====":
break;
s = binascii.a2b_base64 (l)
if type (s) == type (''):
g.write (s)
# possible prompts
f.read (("#", "$", ">"))
f.write ("exit\n")
f.read ()
|