[Twisted-Python] Patch for tap.ftp to add username and password options

Amir Bakhtiar ab at pobox.com
Wed Feb 26 15:08:01 EST 2003


This patch allows username and password pairs to be defined.
e.g. mktap ftp -uamir -pfoo
       mktap ftp -uamir:glyph -pfoo:bar

-A-

--- ftp.py 2003-02-26 11:31:15.000000000 -0800
+++ ftp.new.py 2003-02-26 11:43:16.000000000 -0800
@@ -33,13 +33,33 @@
     optParameters = [
         ["port", "p", "2121",                 "set the port number"],
         ["root", "r", "/usr/local/ftp",       "define the root of the
ftp-site."],
-        ["useranonymous", "", "anonymous",    "Name of the anonymous
user."]
+        ["useranonymous", "", "anonymous",    "Name of the anonymous
user."],
+        ["username(s)", "u", "twisted","set the login username. colon
separate for multiple."],
+        ["password(s)", "w", "twisted","set the password. colon separate
for multiple."]
     ]
     optFlags = [["anonymous", "a","allow anonymous logins"],
                 ["thirdparty", "3", "allow third-party
connections"],diff -c
                 ["otp", "","activate One-Time Passwords"]]

     longdesc = ''
+
+
+    def opt_username(self, username):
+        """Set the login username(s).
+        This can be a single username or a ':' separated
+        list of usernames.
+        """
+        self.opts['username'] = username
+    opt_u = opt_username
+
+
+    def opt_password(self, password):
+        """Set the login username(s).
+        This can be a single password or a ':' separated
+        list of passwords.
+        """
+        self.opts['password'] = password
+    opt_w = opt_password


 def addUser(factory, username, password):
@@ -60,8 +80,15 @@
     t.otp = config.opts['otp']
     t.userdict = {}

-    # adding a default user
-    addUser(t, "twisted", "twisted")
+    if config.opts['username']:
+        # Adding specified users
+        unames = config.opts['username'].split(':')
+        pwords = config.opts['password'].split(':')
+        for u, p in zip(unames, pwords):
+            addUser(t, u, p)
+    else:
+        # Adding a default user
+        addUser(t, "twisted", "twisted")

     try:
         portno = int(config.opts['port'])






More information about the Twisted-Python mailing list