[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

write to remote ile

monkeys paw

3/8/2010 2:10:00 AM

I can xfer a file from a remote server using:

import urllib2 as u
x=u.urlopen('http://tycho.usno.navy.mil/cgi-bin/tim...)

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/somefil..., 'w')

but that does not work
6 Answers

Martin P. Hellwig

3/8/2010 2:20:00 AM

0

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/tim...)
>
> 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/somefil..., 'w')
>
> but that does not work

How do you normally (i.e. without python) put files on a remote server?

--
mph

monkeys paw

3/8/2010 2:51:00 AM

0

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/tim...)
>>
>> 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/somefil..., '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

Martin P. Hellwig

3/8/2010 2:54:00 AM

0

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/tim...)
>>>
>>> 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/somefil..., '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/f...

--
mph

monkeys paw

3/8/2010 8:31:00 PM

0

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/tim...)
>>>>
>>>> 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/somefil..., '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/f...
>

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

MRAB

3/8/2010 10:48:00 PM

0

monkeys paw wrote:
> 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/tim...)
>>>>>
>>>>> 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/somefil..., '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/f...
>>
>
> 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>
>
The documentation says:

FTP.storlines(cmd, file, callback=None)

where 'cmd' is the FTP command, 'STOR sf.xml' ('sf.xl' is the path of
the file on the server) and 'file' is the open (local) source file.

Dennis Lee Bieber

3/9/2010 6:52:00 AM

0

On Mon, 08 Mar 2010 15:30:39 -0500, monkeys paw <monkey@joemoney.net>
declaimed the following in gmane.comp.python.general:

> ftp.storlines('STOR', 'sf.xml') # Is this incorrect, it throws error>

Error 1: You didn't supply the destination file name on the STOR
command

Error 2: You didn't supply an open file object from which to retrieve
the lines to be transferred

myfile = open(local_file_name, "rt")
ftp.storlines("STOR sf.xml", myfile)
myfile.close()

All of which you could have found by reading the standard library
documentation supplied with Python.

>From the help system:
-=-=-=-=-=-=-
storbinary( command, file[, blocksize])

Store a file in binary transfer mode. command should be an appropriate
"STOR" command: "STOR filename". file is an open file object which is
read until EOF using its read() method in blocks of size blocksize to
provide the data to be stored. The blocksize argument defaults to 8192.
Changed in version 2.1: default for blocksize added.

storlines( command, file)

Store a file in ASCII transfer mode. command should be an appropriate
"STOR" command (see storbinary()). Lines are read until EOF from the
open file object file using its readline() method to provide the data to
be stored.
-=-=-=-=-=-=-

--
Wulfraed Dennis Lee Bieber KD6MOG
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/