Python FTP issues

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • fredniggle
    New Member
    • Jan 2008
    • 12

    #1

    Python FTP issues

    Hello,

    This is my first post here, and i'd like to thank you in advance for any help you can provide.

    While working on a python program to make HTML pages, i have encountered a problem when it comes to <br>
    uploading the pages.

    The 'sandbox' script which i am using to test my methods is:::
    Code:
    import sys, os, ftplib, MOD
    print"running"
    #oooo this is insert
    s = ftplib.FTP('ftp.members.lycos.co.uk','myusername','mypassword') # Connect
    print "Connect"
    ndsfile = r"c:\index.html"
    xnds = "STOR "+ndsfile
    f = open(ndsfile,'r')               # file to send
    xcv=ftp.getwelcome()
    print xcv
    print xnds
    ftp.storlines('STOR index.html', f)
    f.close()                           # Close file and FTP
    s.quit()
    print "done!"
    When i run this Pythonwin generates the following output:
    running
    Connect
    220 212.78.204.231 FTP server ready
    STOR c:\index.html

    Traceback (innermost last):
    File "e:\Program Files\Python\Py thonwin\pywin\f ramework\script utils.py", line 301, in RunScript
    exec codeObject in __main__.__dict __
    File "C:\Documen ts and Settings\dave\D esktop\ftplearn 1.py", line 12, in ?
    ftp.storlines(' STOR index.html', f)
    File "e:\Program Files\Python\Li b\ftplib.py", line 374, in storlines
    self.voidcmd('T YPE A')
    File "e:\Program Files\Python\Li b\ftplib.py", line 232, in voidcmd
    self.putcmd(cmd )
    File "e:\Program Files\Python\Li b\ftplib.py", line 162, in putcmd
    self.putline(li ne)
    File "e:\Program Files\Python\Li b\ftplib.py", line 157, in putline
    self.sock.send( line)
    File "<string>", line 1, in send
    error: (10053, 'winsock error')
    >>>

    As can be seen the program shows the welcome message from the server, so i know that the <br>
    connection is ready, and i have used examples from all over the WWW to try<vr>
    to correct the upload problem.

    I am running version 1.5.2+ of pythonwin on XP service pack 2 with avast <br>
    antivirus ( i am unsure if the windows firewall is working due to a current <br>problem with the WMI!)

    ANy help or suggestions will be hugely appreciated!
  • fredniggle
    New Member
    • Jan 2008
    • 12

    #2
    Update on FTP issue:

    Can anyone PLEASE help?
    I've been plugging away at this when ive had the chance.

    Having restructured the code, and after trying different approaches as suggested by various sources, the program now looks like this:

    Code:
    import sys, os, ftplib, MOD
    print"running"
    print
    ndsFTPtry = ftplib.FTP('ftp.members.lycos.co.uk','username','password') # Connect
    print "Test Connection OPEN"
    print
    xndscv=ndsFTPtry.getwelcome()
    print xndscv
    print
    ndsFTPtry.quit()
    print "Test Connection CLOSED"
    print
    #oooo this is insert
    s = ftplib.FTP('ftp.members.lycos.co.uk','username','pass') # Connect
    print "Connection re Opened"
    print
    ndsfile = r"c:\index.html"
    xnds = "STOR "+ndsfile
    f = open(ndsfile,'r')               # file to send
    print "index.htm is opened for reading"
    zxnds= f.readlines()
    print "file read ::"
    print zxnds
    print
    print
    xcv=s.getwelcome()
    print xcv
    print xnds
    s.cwd("/")
    print "directory set"
    #s.port("21")
    print "port set"
    s.storlines("STOR index.htm", f)
    print "File uploaded"
    f.close()                           # Close file and FTP
    print "File is CLOSED"
    s.quit()
    print "done!"
    Which now generates the following output from Pythonwin:
    PythonWin 1.5.2+ (#0, Oct 1 2004, 15:39:52) [MSC 32 bit (Intel)] on win32.
    Portions Copyright 1994-2001 Mark Hammond (mhammond@skipp inet.com.au) - see 'Help/About PythonWin' for further copyright information.
    >>> running

    Test Connection OPEN

    220 212.78.204.231 FTP server ready

    Test Connection CLOSED

    Connection re Opened

    index.htm is opened for reading
    file read ::
    ['<!doctype html public "-//w3c//dtd html 4.0 transitional//en">\012', '<html>\012', '<head>\012', ' <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\012', ' <meta name="GENERATOR " content="Mozill a/4.79 [en] (Windows NT 5.0; U) [Netscape]">\012', ' <title>FREDSPOS TS</title>\012', '</head>\012', '<body text="#FFFFFF" bgcolor="#00006 6" link="#FF6600" vlink="#009900" alink="#FF9900" >\012', '<tt>Please visit back soon:</tt>\012', '<br>&nbsp;\012 ', '<blockquote>\0 12', '<blockquote><t t>Posted at 17:52 on 3-1-08</tt>\012', '<p><tt>Error. </tt>\012', '<br><tt>Page update in progress.</tt>\012', '<p><tt>Please retry soon.</tt></blockquote>\012 ', '</blockquote>\012 ', '\012', '<p><br><tt>FRE DS POSTS::</tt>\012', '<br>&nbsp;\012 ', '</body>\012', '</html>\012']


    220 212.78.204.231 FTP server ready
    STOR c:\index.html
    directory set
    port set
    Traceback (innermost last):
    File "e:\Program Files\Python\Py thonwin\pywin\f ramework\script utils.py", line 301, in RunScript
    exec codeObject in __main__.__dict __
    File "C:\Documen ts and Settings\dave\D esktop\ftplearn 1.py", line 33, in ?
    s.storlines("ST OR index.htm", f)
    File "e:\Program Files\Python\Li b\ftplib.py", line 375, in storlines
    conn = self.transfercm d(cmd)
    File "e:\Program Files\Python\Li b\ftplib.py", line 285, in transfercmd
    return self.ntransferc md(cmd)[0]
    File "e:\Program Files\Python\Li b\ftplib.py", line 273, in ntransfercmd
    resp = self.sendcmd(cm d)
    File "e:\Program Files\Python\Li b\ftplib.py", line 228, in sendcmd
    return self.getresp()
    File "e:\Program Files\Python\Li b\ftplib.py", line 199, in getresp
    raise error_temp, resp
    ftplib.error_te mp: 421 No Transfer Timeout (300 seconds): closing control connection.
    >>>

    When i check the site I find an empty file titled index.html!

    Comment

    • fredniggle
      New Member
      • Jan 2008
      • 12

      #3
      Hello again,

      I keep trawling the web looking for help with my FTP issue, and i keep seeing examples of code where ftp.stobinary is used to upload text files! Is this because of trouble with using storlines?

      Comment

      Working...