An FTP Client...My first real program!

T

tmallen

Here's the code:http://pastebin.com/m21dfcc19

What could be improved? The script feels clumsy, and I have no
experience refactoring Python code. This will eventually be a GUI FTP
client. I'm mainly looking for design advice...

Note that all it does right now is store account info and connect to
the host, listing the contents of the pwd. Anonymous connections work,
and the script is functionally sound.
 
S

s0suk3

Here's the code:http://pastebin.com/m21dfcc19

What could be improved? The script feels clumsy, and I have no
experience refactoring Python code. This will eventually be a GUI FTP
client. I'm mainly looking for design advice...

Well of course it could be improved, so far you've got less than 50
lines :). You're on the starting-from-scratch phase.

Here's my advice: Since you're a beginner (basing on the title of the
thread), and are probably doing this for educational purposes, I'd
recommend you not to use the ftplib module. Doing Internet protocol
implementations is lots of fun. But with Python, which has modules for
most of the popular protocols, you'll probably never need to do
anything like this manually. Most Internet protocols are defined by
some sort of standard, usually an RFC. FTP's is RFC 959 (http://
www.ietf.org/rfc/rfc0959.txt). (This recommendation is of course
directed to you in particular; in production code it would be
generally better to use the ftplib module.)

Sebastian
 
P

Python Nutter

ery low level and not very useful for beginners as a lot of the heavy
lifting and management is still left up to you, the programmer.

The module ftputil is a high-level interface to the ftplib module. The
FTPHost objects generated from it allow many operations similar to
those of os and os.path. An example:

# download some files from the login directory
host = ftputil.FTPHost('ftp.domain.com', 'user', 'secret')
names = host.listdir(host.curdir)
for name in names:
if host.path.isfile(name):
host.download(name, name, 'b') # remote, local, binary mode
# make a new directory and copy a remote file into it
host.mkdir('newdir')
source = host.file('index.html', 'r') # file-like object
target = host.file('newdir/index.html', 'w') # file-like object
host.copyfileobj(source, target) # similar to shutil.copyfileobj
source.close()
target.close()


Now if you are again purely in it for a challenge or for and
educational roller coaster ride, ignore the suggestion to look at
higher level ftp modules =)

Cheers,
PN
 
P

Python Nutter

sorry cut off due to original email being sent not to the list due to gmail:

A second for that suggestion--the ftp module in the python standard library is
very low level and not very useful for beginners as a lot of the heavy
lifting and management is still left up to you, the programmer.
 
T

tmallen

sorry cut off due to original email being sent not to the list due to gmail:

A second for that suggestion--the ftp module in the python standard library is
very low level and not very useful for beginners as a lot of the heavy
lifting and management is still left up to you, the programmer.

What work, specifically, am I duplicating? I have my eyes on a larger
application, so if this part can easily be taken care of, I'm all ears.
 
T

tmallen

What work, specifically, am I duplicating? I have my eyes on a larger
application, so if this part can easily be taken care of, I'm all ears.

I see that there's this ftputil module. Are there any modules already
written for other clients, e.g. CVS, Subversion, Git, etc?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top