Skip to content
Snippets Groups Projects
Commit 8aa5638c authored by Per Cederqvist's avatar Per Cederqvist
Browse files

New demonstration. Get a directory listing from two ftp servers,

simultaneously.
parent cbbf8747
No related branches found
No related tags found
No related merge requests found
# A more complex ftp example. This one connects to two ftp servers,
# does a "cd pub" on both, and prints a directory listing. This is
# done in parallell, so the output from the fastest server will be
# printed first. You could use this program as a kind of poor mans
# ftp server benchmark.
#
# This also tests the expect_after functionality.
import pcl_expect
pcl_expect.stty_init = "-onlcr -ocrnl -echo"
funet = pcl_expect.spawn("ftp ftp.funet.fi")
sunet = pcl_expect.spawn("ftp ftp.sunet.se")
def name_cb(ftp):
ftp.send("anonymous\n")
return pcl_expect.CONT
def password_cb(ftp):
ftp.send("ceder@lysator.liu.se\n")
return pcl_expect.CONT
cmds = {}
cmds[funet] = ["cd pub\n", "passive\n", "dir\n"]
cmds[sunet] = ["cd pub\n", "passive\n", "dir\n"]
printed = 0
def prompt_cb(ftp):
global printed
if len(cmds[ftp]) > 0:
ftp.send(cmds[ftp][0])
cmds[ftp] = cmds[ftp][1:]
else:
print ftp.match.group()
printed += 1
pcl_expect.debug("STATE: cmds[sunet] = %s\n" % cmds[sunet])
pcl_expect.debug("STATE: cmds[funet] = %s\n" % cmds[funet])
if printed < 2:
return pcl_expect.CONT
pcl_expect.expect_after([(pcl_expect.RE, funet, "Name.*:", name_cb),
(pcl_expect.RE, sunet, "Name.*:", name_cb),
(pcl_expect.RE, funet, "Password:", password_cb),
(pcl_expect.RE, sunet, "Password:", password_cb),
(pcl_expect.RE, funet, "(?s).*ftp> ", prompt_cb),
(pcl_expect.RE, sunet, "(?s).*ftp> ", prompt_cb)])
x = pcl_expect.impl()
while x.loop():
pass
sunet.send("bye\n")
funet.send("bye\n")
pcl_expect.expect_after([])
x = pcl_expect.impl()
while x.loop():
if x.eof(sunet):
print "SUNET final output:", sunet.match
sunet.close()
x = pcl_expect.impl()
while x.loop():
if x.eof(funet):
print "FUNET final output:", funet.match
funet.close()
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment