diff --git a/demo/ftp.py b/demo/ftp.py new file mode 100644 index 0000000000000000000000000000000000000000..a7748dbdd461b96da2c022efb6b6d8b7272f31ef --- /dev/null +++ b/demo/ftp.py @@ -0,0 +1,43 @@ +# The mandatory ftp example... + +import pcl_expect + +pcl_expect.stty_init = "-onlcr -ocrnl" + +ftp = pcl_expect.spawn("ftp ftp.funet.fi") + +x = pcl_expect.impl() +while x.loop(): + if x.re(ftp, "Name.*:"): + ftp.send("anonymous\n") + x.cont() + continue + elif x.re(ftp, "Password:"): + ftp.send("ceder@lysator.liu.se\n") + x.cont() + continue + elif x.re(ftp, "ftp> "): + pass + +ftp.send("cd pub\n") + +x = pcl_expect.impl() +while x.loop(): + if x.re(ftp, "(?s).*ftp> "): + pass + +ftp.send("passive\n") + +x = pcl_expect.impl() +while x.loop(): + if x.re(ftp, "(?s).*ftp> "): + pass + +ftp.send("dir\n") + +x = pcl_expect.impl() +while x.loop(): + if x.re(ftp, "(?s).*ftp> "): + print ftp.match.group() + +ftp.close()