Re: Using a Callback Function - ftplib

2009-08-19 Thread seldan24
On Aug 18, 6:02 am, Nitebirdz nitebi...@sacredchaos.com wrote:
 On Mon, Aug 17, 2009 at 11:10:25AM -0700, seldan24 wrote:

  I didn't even notice the higher level methods.  I changed the
  retrieval line to:

  ftp.nlst(testfile*.txt)

  This works great.  The result is even captured in an array.  I really
  have no idea what the difference between a LIST and NLST is within
  FTP.  Never delved that deep into it.  I did notice that an NLST will
  return a specific FTP code if a file doesn't exist, whereas a LIST
  doesn't.  So, I ended up using NLST as that'll generate an
  ftplib.error_perm exception.  Based on if the job cares if a file is
  not available or not (some do, some don't), I'll either exit, or
  continue on with the file loop.

 The following thread from a NetBSD mailing list may help clarify this
 issue:

 http://mail-index.netbsd.org/netbsd-users/2001/01/30/0016.html

 NLST returns a machine-readable list of names, while LIST returns a
 human-readable list.  Hene the presence of the FTP code in the case of
 NLST.  

Nitebirdz,

Thanks for the information.  I knew it stood for 'named list' but had
no idea how that differed from the standard.  I appreciate the link.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using a Callback Function - ftplib

2009-08-19 Thread nitebirdz
On Mon, Aug 17, 2009 at 11:10:25AM -0700, seldan24 wrote:
 
 I didn't even notice the higher level methods.  I changed the
 retrieval line to:
 
 ftp.nlst(testfile*.txt)
 
 This works great.  The result is even captured in an array.  I really
 have no idea what the difference between a LIST and NLST is within
 FTP.  Never delved that deep into it.  I did notice that an NLST will
 return a specific FTP code if a file doesn't exist, whereas a LIST
 doesn't.  So, I ended up using NLST as that'll generate an
 ftplib.error_perm exception.  Based on if the job cares if a file is
 not available or not (some do, some don't), I'll either exit, or
 continue on with the file loop.
 

The following thread from a NetBSD mailing list may help clarify this
issue:

http://mail-index.netbsd.org/netbsd-users/2001/01/30/0016.html


NLST returns a machine-readable list of names, while LIST returns a
human-readable list.  Hene the presence of the FTP code in the case of
NLST.  

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


Re: Using a Callback Function - ftplib

2009-08-18 Thread Nitebirdz
On Mon, Aug 17, 2009 at 11:10:25AM -0700, seldan24 wrote:
 
 I didn't even notice the higher level methods.  I changed the
 retrieval line to:
 
 ftp.nlst(testfile*.txt)
 
 This works great.  The result is even captured in an array.  I really
 have no idea what the difference between a LIST and NLST is within
 FTP.  Never delved that deep into it.  I did notice that an NLST will
 return a specific FTP code if a file doesn't exist, whereas a LIST
 doesn't.  So, I ended up using NLST as that'll generate an
 ftplib.error_perm exception.  Based on if the job cares if a file is
 not available or not (some do, some don't), I'll either exit, or
 continue on with the file loop.
 

The following thread from a NetBSD mailing list may help clarify this
issue:

http://mail-index.netbsd.org/netbsd-users/2001/01/30/0016.html


NLST returns a machine-readable list of names, while LIST returns a
human-readable list.  Hene the presence of the FTP code in the case of
NLST.  

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


Using a Callback Function - ftplib

2009-08-17 Thread seldan24
Hello,

I'm utterly confused by something which is most likely trivial.  I'm
attempting to connect to an FTP server, retrieve a list of files, and
store than in an array.  I.e.:

import ftplib

ftp = ftplib.FTP(server)
ftp.login(user, pass)
ftp.cwd(conf['testdir'])
ftp.retrlines('NLST ' + testfile*.txt)
ftp.quit()

The above example works fine... and would return a list of any files
that match testfile*.txt to standard out.  The issue is I don't want
that to go to stdout, I'd rather capture them within an array so I can
retrieve them later.

If I try something like:

my_files = ftp.retrlines('NLST ' + testfile*.txt)

Then, my_files, will just print out the return code of the FTP NLST
command.  I'm trying to get the file names themselves.  Now, I've read
through the ftplib module section of the Python documentation and it
says that, by default, the output goes to sys.stdout unless a callback
function is used.  Here is where I get utterly lost.  I can certainly
see the files being outputted to sys.stdout, but don't know how to
capture that output... i.e.

testfile1.txt
testfile2.txt
testfile3.txt

Will show to the screen, but I can't catch it!  I'm sure this is
trivial... any help would be greatly appreciated.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Using a Callback Function - ftplib

2009-08-17 Thread David
Il Mon, 17 Aug 2009 10:43:33 -0700 (PDT), seldan24 ha scritto:

 Hello,
 
 I'm utterly confused by something which is most likely trivial.  I'm
 attempting to connect to an FTP server, retrieve a list of files, and
 store than in an array.  I.e.:
 
 import ftplib
 
 ftp = ftplib.FTP(server)
 ftp.login(user, pass)
 ftp.cwd(conf['testdir'])

Why bother with retrlines? Use the provided higer level fuctions:

remotefiles = []
ftp.dir(remotefiles.append)

or, if you prefer nlst

remotefiles = ftp.nlst()

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


Re: Using a Callback Function - ftplib

2009-08-17 Thread seldan24
On Aug 17, 1:51 pm, David 71da...@libero.it wrote:
 Il Mon, 17 Aug 2009 10:43:33 -0700 (PDT), seldan24 ha scritto:

  Hello,

  I'm utterly confused by something which is most likely trivial.  I'm
  attempting to connect to an FTP server, retrieve a list of files, and
  store than in an array.  I.e.:

  import ftplib

  ftp = ftplib.FTP(server)
  ftp.login(user, pass)
  ftp.cwd(conf['testdir'])

 Why bother with retrlines? Use the provided higer level fuctions:

 remotefiles = []
 ftp.dir(remotefiles.append)

 or, if you prefer nlst

 remotefiles = ftp.nlst()

 regards
 david

I didn't even notice the higher level methods.  I changed the
retrieval line to:

ftp.nlst(testfile*.txt)

This works great.  The result is even captured in an array.  I really
have no idea what the difference between a LIST and NLST is within
FTP.  Never delved that deep into it.  I did notice that an NLST will
return a specific FTP code if a file doesn't exist, whereas a LIST
doesn't.  So, I ended up using NLST as that'll generate an
ftplib.error_perm exception.  Based on if the job cares if a file is
not available or not (some do, some don't), I'll either exit, or
continue on with the file loop.

Anyway, thanks again, works perfectly, next time I'll try to scroll
down and read a bit more prior to posting!
-- 
http://mail.python.org/mailman/listinfo/python-list