write to remote ile

monkeys paw monkey at joemoney.net
Mon Mar 8 21:30:39 CET 2010


On 3/7/2010 9:53 PM, Martin P. Hellwig wrote:
> On 03/08/10 02:51, monkeys paw wrote:
>> On 3/7/2010 9:20 PM, Martin P. Hellwig wrote:
>>> On 03/08/10 02:10, monkeys paw wrote:
>>>> I can xfer a file from a remote server using:
>>>>
>>>> import urllib2 as u
>>>> x=u.urlopen('http://tycho.usno.navy.mil/cgi-bin/timer.pl')
>>>>
>>>> for line in x:
>>>> print line
>>>>
>>>>
>>>> How can i write a file to the remote server?
>>>>
>>>> I tried:
>>>>
>>>> x = u.url.open('http://joemoney.net/somefile.txt', 'w')
>>>>
>>>> but that does not work
>>>
>>> How do you normally (i.e. without python) put files on a remote server?
>>>
>> Using FTP, i'm really having a brain cramp here, but i'm new to python
>
> We all been there, in some for or other ;-), anyway you might want to
> have a look at this:
> http://docs.python.org/library/ftplib.html
>

Tried this, the storlines doesn't work, everything else OK

from ftplib import FTP
ftp = FTP('joemoney.net')
ftp.login('secret','pw')
ftp.retrlines('LIST')     # list directory contents
ftp.storlines('STOR', 'sf.xml')   # Is this incorrect, it throws error>

   File "ftp.py", line 5, in <module>
     ftp.storlines('STOR', 'sf.xml')
   File "C:\Python26\lib\ftplib.py", line 470, in storlines
     conn = self.transfercmd(cmd)
   File "C:\Python26\lib\ftplib.py", line 356, in transfercmd
     return self.ntransfercmd(cmd, rest)[0]
   File "C:\Python26\lib\ftplib.py", line 327, in ntransfercmd
     resp = self.sendcmd(cmd)
   File "C:\Python26\lib\ftplib.py", line 243, in sendcmd
     return self.getresp()
   File "C:\Python26\lib\ftplib.py", line 218, in getresp
     raise error_perm, resp
ftplib.error_perm: 501 No file name


The file exists in the same directory as ftp.py



More information about the Python-list mailing list