From b4a4aa2fc73a71157dbcee907496494f2895fab9 Mon Sep 17 00:00:00 2001
From: Per Cederqvist <ceder@lysator.liu.se>
Date: Fri, 10 Oct 2003 16:37:24 +0000
Subject: [PATCH] New demo program, that uses the traditional API.

---
 demo/ftptrad.py | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)
 create mode 100644 demo/ftptrad.py

diff --git a/demo/ftptrad.py b/demo/ftptrad.py
new file mode 100644
index 0000000..84028cf
--- /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()
-- 
GitLab