diff --git a/demo/ftptrad.py b/demo/ftptrad.py new file mode 100644 index 0000000000000000000000000000000000000000..84028cfdacdd6ff80c0a60f2d40a79bd497fced5 --- /dev/null +++ b/demo/ftptrad.py @@ -0,0 +1,40 @@ +# The mandatory ftp example, in traditional style. + +import pcl_expect + +pcl_expect.stty_init = "-onlcr -ocrnl" + +ftp = pcl_expect.spawn("ftp ftp.funet.fi") + +def send_anon(exp): + exp.send("anonymous\n") + return pcl_expect.CONT + +def send_user(exp): + exp.send("ceder@lysator.liu.se\n") + return pcl_expect.CONT + +ret, exp = pcl_expect.expect([ + (pcl_expect.RE, ftp, "Name.*:", send_anon), + (pcl_expect.RE, ftp, "Password.*:", send_user), + (pcl_expect.RE, ftp, "ftp> "), + ]) + +assert ret == 2 +assert exp == ftp + +ftp.send("cd pub\n") + +pcl_expect.expect([(pcl_expect.RE, ftp, "(?s).*ftp> ")]) + +ftp.send("passive\n") + +pcl_expect.expect([(pcl_expect.RE, ftp, "(?s).*ftp> ")]) + +ftp.send("dir\n") + +ret, exp = pcl_expect.expect([(pcl_expect.RE, ftp, "(?s).*ftp> ")]) +if ret == 0: + print ftp.match.group() + +ftp.close()