Hi,

I am a newbie to python in general and rpyc in particular. Please forgive 
my ignorance.

How can I achieve file transfer.

I added the file open part in my service.py in server. And then I ran both 
my own rpyc service and rpyc_classic.py.

Now I use the client to to copy_to_server and I still get the write error.

Any help is appreciated.

Best Regards,
Vishwanath


On Tuesday, 17 February 2009 18:22:05 UTC+5:30, Tomer Filiba wrote:
>
> nice, but you might want to check out rpyc/utils/classic.py -- it already 
> has file transfer functionality :)
> it does require the classic mode, but assuming you can get a remote file 
> object,
> you can just use shutil.copyfileobj (you should check out shutil, btw, if 
> you're new to python)
>
> i.e.
>
> # == server ==
> class FileService(rpyc.Service):
>     def exposed_open(self, filename, mode = "r"):
>         return open(filename, mode)
>
> # == client ==
> c = rpyc.connect(host, port)
>
> # copy to client
> remote = c.root.open("/foo/bar")
> local = open("/tmp/foo/bar", "w")
> shutil.copyfileobj(remote, local)
>
> # copy to server
> local = open("/spam/bacon")
> remote = c.root.open("/tmp/spam/bacon", "w")
> shutil.copyfileobj(local, remote)
>
>
> hope it helps,
> -tomer
>
>
> On Tue, Feb 17, 2009 at 14:30, CinnamonDonkey 
> <[email protected]<javascript:>
> > wrote:
>
>>
>> No worries! I worked it out :)
>>
>> SERVER SHOULD BE:
>>
>>  class MyService( rpyc.Service ):
>>    class exposed_FileTransfer(  ):
>>       def exposed_Open( self, filename ):
>>         print "FILE TRANSFER OPEN FUNCTION CALLED - " + filename
>>        return 0
>>
>>  if __name__ == "__main__":
>>    s = ThreadedServer( MyService, port = 1234, reuse_addr = True )
>>    s.start()
>>
>>
>> CLIENT SHOULD BE:
>>
>>  if __name__ == "__main__":
>>    connection = rpyc.connect( options.serviceHostName,
>> options.servicePortNum )
>>     tf = connection.root.FileTransfer()
>>    tf.Open(  "SPANKING~!!!" )
>>
>>
>>
>> On 17 Feb, 12:25, CinnamonDonkey <[email protected]>
>> wrote:
>> > I have written this on my server side:
>> >
>> >   class MyService( rpyc.Service ):
>> >     class exposed_FileTransfer(  ):
>> >       def exposed_Open( filename ):
>> >         print "FILE TRANSFER OPEN FUNCTION CALLED - " + filename
>> >         return 0
>> >
>> >   if __name__ == "__main__":
>> >     s = ThreadedServer( MyService, port = 1234, reuse_addr = True )
>> >     s.start()
>> >
>> > But on my client side I can't figure how to call it. I have tried:
>> >
>> >   if __name__ == "__main__":
>> >     connection = rpyc.connect( options.serviceHostName,
>> > options.servicePortNum )
>> >     connection.root.FileTransfer.Open( "SPANKING~!!!" )
>> >
>> > But I get the error:
>> >
>> >   TypeError: unbounded method expose_Open() must be called with
>> > exposed_FileTransfer instance as first argument.
>> >
>> > eh? I tried:
>> >
>> >   if __name__ == "__main__":
>> >     connection = rpyc.connect( options.serviceHostName,
>> > options.servicePortNum )
>> >     ft = connection.root.FileTransfer
>> >     ft.Open( "SPANKING~!!!" )
>> >
>> > and that does not work... I'm confussed.
>> >
>> > Please help.
>> >
>> > On 17 Feb, 09:17, CinnamonDonkey <[email protected]>
>> > wrote:
>> >
>> > > Thanx for the reply RedBaron.
>> >
>> > > I agree, I don't think it is the best way of doing a file transfer but
>> > > based on my limited knowledge of Python and RPyC I'd rather spend my
>> > > time learning a few systems well than lots of systems badly. At least
>> > > that is my theory at the moment, everything is subject to change ;-).
>> >
>> > > I do need, RPC for some genuine tasks later so I figured this would be
>> > > a good starting point as it satisfies two goals. How to transfer my
>> > > file and how to use RPyC :-D.
>> >
>> > > I have to say, I am very impressed with this Python'ing lark... Oh
>> > > what I have been missing all these years ;-).
>> >
>> > > On 17 Feb, 09:05, redbaron <[email protected]> wrote:
>> >
>> > > > Are you sure that RPyC is a good way to do it? I'm not sure but try 
>> to
>> > > > open file and then send file handler to remote service. As it said 
>> in
>> > > > docs all objects are passed by reference, so reading from that 
>> handler
>> > > > on remote side will actually make transfer from local machine to
>> > > > remote onee. I'm not sure will it work or not, but you could try it 
>> =)
>> >
>> > > > f = open(/path/to/file,"rb")
>> > > > ... send of on remote side
>> > > > ....do f.read() on remote side.
>> >
>> > > > be careful that f.read() will allocate memory equal to file size, if
>> > > > its really big then try to read it chunk by chunk like:
>> >
>> > > > g = open("/path/where/to/write","wb")
>> > > > chunk = f.read(1024*1024)
>> > > > while chunk:
>> > > >   g.write(chunk)
>> > > >   chunk = f.read(1024*1024)
>> >
>> >
>>
>
>
>
> -- 
> An NCO and a Gentleman
>  

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"rpyc" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to