471,354 Members | 1,632 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

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:::
Expand|Select|Wrap|Line Numbers
  1. import sys, os, ftplib, MOD
  2. print"running"
  3. #oooo this is insert
  4. s = ftplib.FTP('ftp.members.lycos.co.uk','myusername','mypassword') # Connect
  5. print "Connect"
  6. ndsfile = r"c:\index.html"
  7. xnds = "STOR "+ndsfile
  8. f = open(ndsfile,'r')               # file to send
  9. xcv=ftp.getwelcome()
  10. print xcv
  11. print xnds
  12. ftp.storlines('STOR index.html', f)
  13. f.close()                           # Close file and FTP
  14. s.quit()
  15. print "done!"
  16.  
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\Pythonwin\pywin\framework\scriptutils .py", line 301, in RunScript
exec codeObject in __main__.__dict__
File "C:\Documents and Settings\dave\Desktop\ftplearn1.py", line 12, in ?
ftp.storlines('STOR index.html', f)
File "e:\Program Files\Python\Lib\ftplib.py", line 374, in storlines
self.voidcmd('TYPE A')
File "e:\Program Files\Python\Lib\ftplib.py", line 232, in voidcmd
self.putcmd(cmd)
File "e:\Program Files\Python\Lib\ftplib.py", line 162, in putcmd
self.putline(line)
File "e:\Program Files\Python\Lib\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!
Jan 5 '08 #1
2 4594
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:

Expand|Select|Wrap|Line Numbers
  1. import sys, os, ftplib, MOD
  2. print"running"
  3. print
  4. ndsFTPtry = ftplib.FTP('ftp.members.lycos.co.uk','username','password') # Connect
  5. print "Test Connection OPEN"
  6. print
  7. xndscv=ndsFTPtry.getwelcome()
  8. print xndscv
  9. print
  10. ndsFTPtry.quit()
  11. print "Test Connection CLOSED"
  12. print
  13. #oooo this is insert
  14. s = ftplib.FTP('ftp.members.lycos.co.uk','username','pass') # Connect
  15. print "Connection re Opened"
  16. print
  17. ndsfile = r"c:\index.html"
  18. xnds = "STOR "+ndsfile
  19. f = open(ndsfile,'r')               # file to send
  20. print "index.htm is opened for reading"
  21. zxnds= f.readlines()
  22. print "file read ::"
  23. print zxnds
  24. print
  25. print
  26. xcv=s.getwelcome()
  27. print xcv
  28. print xnds
  29. s.cwd("/")
  30. print "directory set"
  31. #s.port("21")
  32. print "port set"
  33. s.storlines("STOR index.htm", f)
  34. print "File uploaded"
  35. f.close()                           # Close file and FTP
  36. print "File is CLOSED"
  37. s.quit()
  38. print "done!"
  39.  
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@skippinet.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="Mozilla/4.79 [en] (Windows NT 5.0; U) [Netscape]">\012', ' <title>FREDSPOSTS</title>\012', '</head>\012', '<body text="#FFFFFF" bgcolor="#000066" link="#FF6600" vlink="#009900" alink="#FF9900">\012', '<tt>Please visit back soon:</tt>\012', '<br>&nbsp;\012', '<blockquote>\012', '<blockquote><tt>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>FREDS 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\Pythonwin\pywin\framework\scriptutils .py", line 301, in RunScript
exec codeObject in __main__.__dict__
File "C:\Documents and Settings\dave\Desktop\ftplearn1.py", line 33, in ?
s.storlines("STOR index.htm", f)
File "e:\Program Files\Python\Lib\ftplib.py", line 375, in storlines
conn = self.transfercmd(cmd)
File "e:\Program Files\Python\Lib\ftplib.py", line 285, in transfercmd
return self.ntransfercmd(cmd)[0]
File "e:\Program Files\Python\Lib\ftplib.py", line 273, in ntransfercmd
resp = self.sendcmd(cmd)
File "e:\Program Files\Python\Lib\ftplib.py", line 228, in sendcmd
return self.getresp()
File "e:\Program Files\Python\Lib\ftplib.py", line 199, in getresp
raise error_temp, resp
ftplib.error_temp: 421 No Transfer Timeout (300 seconds): closing control connection.
>>>

When i check the site I find an empty file titled index.html!
Jan 7 '08 #2
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?
Jan 8 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

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.