[NEWBIE] ftplib error?

Steve Holden sholden at holdenweb.com
Wed Jan 16 16:03:18 EST 2002


"Stefan Schwarzer" <s.schwarzer at ndh.net> wrote in message
news:3C45E6EE.7191EA00 at ndh.net...
> Hello Bruce
>
> I can't really help on your original question but have some other
> suggestions.
>
> Bruce Dykes wrote:
> > import ftplib
> > hostname = ftplib.FTP("192.168.13.21")
>
> I agree with the others that the failure may be due a wrong port.
>
> > hostname.login("joeuser","mydogsname")
> > hostname.cwd("$SYSTEM.DATA")    #  see below
>
> Is the directory literally $SYSTEM.DATA or is SYSTEM some environment
> variable? AFAIK, ftplib doesn't support "interpolating" of environment
> variables.
>
> > hostname_numbers = hostname.retrlines("GET ALARMDATA")
>
> I think, it should be RETR instead of GET? Then, retrlines is not so
> similar to file.readlines. :-) From help(ftplib.FTP.retrlines):
>
> Help on method retrlines in module ftplib:
>
> retrlines(self, cmd, callback=None) unbound ftplib.FTP method
>     Retrieve data in line mode.
>     The argument is a RETR or LIST command.
>     The callback function (2nd argument) is called for each line,
>     with trailing CRLF stripped.  This creates a new port for you.
>     print_line() is the default callback.
>
While these are all interesting points, which will be useful down the line,
the traceback:

Traceback (most recent call last):
  File "C:\Python21\Pythonwin\pywin\framework\scriptutils.py", line 301, in
RunScript
    exec codeObject in __main__.__dict__
  File "C:\telex\ftp_test.py", line 2, in ?
    hostname = ftplib.FTP("192.168.13.21")
  File "c:\python21\lib\ftplib.py", line 108, in __init__
    self.connect(host)
  File "c:\python21\lib\ftplib.py", line 118, in connect
    self.sock.connect((self.host, self.port))
  File "<string>", line 1, in connect
error: (10061, 'Connection refused')

shows that the error is occurring in the call to ftplib.FTP().

Therefore Bruce should modify his code to call ftplib.FTP() with no
arguments, then set debuggin on. Something like this:

import ftplib
hostname = ftplib.FTP()
hostname.set_debuglevel(2)
hostname.connect("192.168.13.21")
hostname.login("joeuser","mydogsname")
hostname.cwd("$SYSTEM.DATA")    #  see below
hostname_numbers = hostname.retrlines("GET ALARMDATA")
hostname.quit()
print hostname_numbers

The bottom line, however, is that his client isn't connecting. Until he can
achieve a connection, the rest is just noise, right Bruce?

regards
 Steve
--
Consulting, training, speaking: http://www.holdenweb.com/
Python Web Programming: http://pydish.holdenweb.com/pwp/








More information about the Python-list mailing list