Re: An FTP Client...My first real program!

2008-08-14 Thread tmallen
On Aug 13, 11:53 pm, Python Nutter [EMAIL PROTECTED] wrote:
 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 [EMAIL PROTECTED]:

  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.
--
http://mail.python.org/mailman/listinfo/python-list


Re: An FTP Client...My first real program!

2008-08-14 Thread tmallen
On Aug 14, 9:54 am, tmallen [EMAIL PROTECTED] wrote:
 On Aug 13, 11:53 pm, Python Nutter [EMAIL PROTECTED] wrote:



  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 [EMAIL PROTECTED]:

   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.

I see that there's this ftputil module. Are there any modules already
written for other clients, e.g. CVS, Subversion, Git, etc?
--
http://mail.python.org/mailman/listinfo/python-list


An FTP Client...My first real program!

2008-08-13 Thread 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...
--
http://mail.python.org/mailman/listinfo/python-list


Re: An FTP Client...My first real program!

2008-08-13 Thread tmallen
On Aug 13, 3:27 pm, tmallen [EMAIL PROTECTED] wrote:
 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.
--
http://mail.python.org/mailman/listinfo/python-list


Re: An FTP Client...My first real program!

2008-08-13 Thread s0suk3
On Aug 13, 2:27 pm, tmallen [EMAIL PROTECTED] wrote:
 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

--
http://mail.python.org/mailman/listinfo/python-list


Re: An FTP Client...My first real program!

2008-08-13 Thread 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
--
http://mail.python.org/mailman/listinfo/python-list


Re: An FTP Client...My first real program!

2008-08-13 Thread 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.

2008/8/14 Python Nutter [EMAIL PROTECTED]:
 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

--
http://mail.python.org/mailman/listinfo/python-list