473,320 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 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 4678
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

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

Similar topics

36
by: Andrea Griffini | last post by:
I did it. I proposed python as the main language for our next CAD/CAM software because I think that it has all the potential needed for it. I'm not sure yet if the decision will get through, but...
1
by: bruce | last post by:
hi. i'min a situation where i might need to upgrade python. i have the current version of python for FC3. i might need to have the version for FC4. i built the version that's on FC4 from the...
32
by: siggi | last post by:
@Ben Sizer Hi Ben, in January I received your message re Pygame and Python 2.5: As a Python (and programming ) newbie allow me a - certainly naive - question:
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.