473,378 Members | 1,417 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

An FTP Client...My first real program!

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...
Aug 13 '08 #1
6 1591
On Aug 13, 3:27*pm, tmallen <thomasmal...@gmail.comwrote:
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.
Aug 13 '08 #2
On Aug 13, 2:27*pm, tmallen <th**********@gmail.comwrote:
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

Aug 14 '08 #3
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
Aug 14 '08 #4
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.

2008/8/14 Python Nutter <py**********@gmail.com>:
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
Aug 14 '08 #5
On Aug 13, 11:53*pm, "Python Nutter" <pythonnut...@gmail.comwrote:
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.

2008/8/14 Python Nutter <pythonnut...@gmail.com>:
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

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.
Aug 14 '08 #6
On Aug 14, 9:54*am, tmallen <thomasmal...@gmail.comwrote:
On Aug 13, 11:53*pm, "Python Nutter" <pythonnut...@gmail.comwrote:
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.
2008/8/14 Python Nutter <pythonnut...@gmail.com>:
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, binarymode
# 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

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?
Aug 14 '08 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Boris Nikolaevich | last post by:
This is backwards of what I usually want--normally if you have a long-running ASP script, it's a good idea to check to see whether the client is still connected so you can cancel execution. ...
7
by: BenignVanilla | last post by:
My ISP provides a web based email client, but it is not brandable and the features are not that extensive. I'd like to build my own. Has anyone done this, or is anyone aware of any tools out there...
15
by: Michael Rybak | last post by:
hi, everyone. I'm writing a 2-players game that should support network mode. I'm now testing it on 1 PC since I don't have 2. I directly use sockets, and both client and server do...
67
by: Mike MacSween | last post by:
I've got a SQL Server database. Nearly finished. It's going to go on a single non networked machine. One day somebody might get access to it over ADSL (probably TS), but for now it's a single user...
5
by: Paul H | last post by:
How do you folks get a reliable and complete brief of what is required before development starts? I am forever going back to a client once a project has started saying "Hang on, now that I've...
2
by: Matt | last post by:
I wrote the tcp socket client-server program that the server will echo the message received from the client. In client program: char sendBuf; while(1) { cout << "Enter message:";...
0
by: Janning Vygen | last post by:
Hi, i have a question about how to handle postgresql constraint errors in the client app. I found some mails in the archive about it, too. But i have still so many questions about how to do it,...
7
by: Chacko | last post by:
Hi could anyone tell me how to simulate multiple clients for a windows form without actually me having to copy paste the code. Cause its a real pain.... The thing is i am working on remoting which...
12
by: bullockbefriending bard | last post by:
I am a complete ignoramus and newbie when it comes to designing and coding networked clients (or servers for that matter). I have a copy of Goerzen (Foundations of Python Network Programming) and...
3
by: Laura | last post by:
Hi: ¿How can I read a file on the client side without loading it to the server?
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.