[Python-Dev] Proposed addition to ftplib (original) (raw)

Jordan Haven jordanhaven at hotmail.com
Tue Feb 3 16:44:18 EST 2004


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 -------------- next part -------------- #ftplib.py function chmod # #Author: Jordan Haven # #This function should be added to the FTP class in the ftplib.py module # #Usage: From within an FTP program, after a connection has been made. Like so: #

ftp_host = raw_input("Host Name: ")

ftp_port = input("Port Number: ")

ftp_user = raw_input("User Name: ")

ftp_pass = getpass.getpass("Password: ")

ftp_acct = raw_input("Account (Leave blank if none): ")

if ftp_user and ftp_pass == "":

ftp = FTP(ftp_host)

ftp.login()

print "Thank you! FTPy is now attempting to connect to %s on port %s"%

(ftp_host, ftp_port)

ftp = FTP(ftp_host)

ftp.connect(ftp_host, ftp_port)

ftp.login(ftp_user, ftp_pass, ftp_acct)

welcome = ftp.getwelcome()

print welcome

def ftpmain():

cmd = raw_input("%s@%s: " %(user, ftp_host))

... code for functions like pwd and cwd, etc. ...

elif cmd == 'chmod':

file = raw_input("File to change permissions: ")

mode = raw_input("CHMOD value: ")

ftp.chmod(mode, file)

ftpmain()

... other code ...

#The above is an example from the FTP program I'm making and is obviously only an example #of the implementation. # #Something to note: 'mode' is a string, not an int so it can be passed as a single command #by the function. # #And now, the actual function:

def chmod(self, mode, file): '''Change file permissions for a file on the remote server.''' return self.voidcmd('SITE CHMOD ' + mode + ' ' + file)



More information about the Python-Dev mailing list