Hey Python developers!
First, since this is my first message to this group, let me introduce myself. My name is Jordan Haven, I'm 16, I live just outside of DC and have been programming for only a few years (~ 2 years). Python was the first language I started, and I have loved it since the beginning.
Now, onto the real purpose of this email. Recently, while creating a CLI FTP program as a precursor to my GUI version (SF project: ftpy), I ran into a roadblock: I couldn't change permissions on the remote file. So I searched the comp.lang.python newsgroup, the python-list archives, these development archives, and countless ftplib tutorials and books and couldn't find anything on chmod'ing files through FTP with the standard ftplib module. So I went through ftplib.py (Python 2.3), and there was no function for chmod'ing files.
I think (and hope you all will agree with me :)) that there needs to be a chmod funtcion included in the ftplib module. So I took the liberty to write one up (see attached). It works fine on my box (Windows 2000 with Python 2.3), and there aren't any obvious backwards compatibility problems that I can see, so the only thing left is to test crossplatform portability. However, looking at the code there doesn't seem to be any issues with that, but if some of you could check it out on various other platforms, I would be most appreciative.
Hopefully it (or a modified version) will make it into the next release of Python.
Well, thank you for your time, and for taking a look at the included function. I look forward to hearing back from you.
-- Jordan Haven
_________________________________________________________________ Find high-speed net deals comparison-shop your local providers here. https://broadband.msn.com
Jordan Haven wrote:
Hopefully it (or a modified version) will make it into the next release of Python.
There is a SF area for Python patches. Sending it there raises the chance that developers will have a look at it: http://sourceforge.net/tracker/?group_id=5470&atid=305470
yours, Gerrit.
PS two years ago, I was also a 16-year-old programmer with 2 years of Python programming experience and Python as a first language and I loved it :-) This situation is still true except that I'm 18 and have 4 years of experience. I am really not a Python developer but just happen to read the Python development mailing list ;-)
On Tue, 2004-02-03 at 17:12, Gerrit Holl wrote:
two years ago, I was also a 16-year-old programmer with 2 years of Python programming experience and Python as a first language and I loved it :-) This situation is still true except that I'm 18 and have 4 years of experience. I am really not a Python developer but just happen to read the Python development mailing list ;-)
Thank you both for making me feel so, um, mature.
at-least-tim's-still-older-than-me-ly y'rs, -Barry
Jordan, It's always good to see people contributing to Python. It's good to have you here.
I have two suggestions about your submission. Well, three. Zeroeth, take the advice of another respondant and use the Sourceforge patch submission interface.
First, when contributing patches to Python, it's most customary to use the Unix tools 'diff' and 'patch' to generate a listing of the changes you made. (If you're a Windows user, perhaps someone can be more helpful than the FAQ entry at http://www.python.org/dev/devfaq.html#how-to-make-a-patch)
Here's the patch for your change:
--- /usr/lib/python2.2/ftplib.py 2003-02-24 18:24:16.000000000 -0600 +++ ./ftplib.py 2004-02-03 19:03:07.000000000 -0600 @@ -469,6 +469,10 @@ cmd = cmd + (' ' + arg) self.retrlines(cmd, func)
+ def chmod(self, mode, file): + '''Change file permissions for a file on the remote server.''' + return self.voidcmd('SITE CHMOD ' + mode + ' ' + file) + def rename(self, fromname, toname): '''Rename a file.''' resp = self.sendcmd('RNFR ' + fromname)
Second, and this may seem foolish because of how little I know about the FTP protocol, I wonder if it makes sense to make the SITE command a method, and have chmod use it. This patch uses that idea, and makes it even easier for you to use more SITE commands easily (well, if it works):
f = ftplib.FTP(...) f.login(...) print f.site('help')
214-The following SITE commands are recognized. UMASK GROUPS IDLE CHECKMETHOD CHMOD ALIAS CHECKSUM HELP CDPATH 214 Direct comments to root@localhost.
f.site('chmod', '644', '/etc/shadow')
ftplib.error_perm: 550 /etc/shadow: Operation not permitted.
--- /usr/lib/python2.2/ftplib.py 2003-02-24 18:24:16.000000000 -0600 +++ ./ftplib.py 2004-02-03 19:17:37.000000000 -0600 @@ -469,6 +469,15 @@ cmd = cmd + (' ' + arg) self.retrlines(cmd, func)
+ def site(self, command, *args): + '''Perform a SITE command with the given arguments.''' + args = " ".join(('SITE', command.upper()) + args) + return self.sendcmd(args) + + def chmod(self, mode, filename): + '''Change file permissions for a file on the remote server.''' + return self.site('chmod', mode, filename) + def rename(self, fromname, toname): '''Rename a file.''' resp = self.sendcmd('RNFR ' + fromname)
Jeff