Using rapi from desktop to copy file from device to desktop

sunnyboyj

Member
It should be so simple, but it's not working.
I have made a simple program (almost the example):

I want to copy the file LGXVRDmu.CSV from my device (in \My Documents) to my desktop computer. I am using activesync and it's connected OK.
Two problems:
1. my programs says 'cannot connect to device.'
2. if i delete this check (rapi.isconneted=true) I get a new error that he can not write.

Sub Button2_Click
rapi.New1
rapi.Connect
t = Now '3 seconds timeout.
Do Until rapi.IsConnected = true
DoEvents
If (Now - t)/cTicksPerSecond > 3 Then
Msgbox("Cannot connect to device.")
AppClose
End If
Loop
If rapi.DeviceFileExists("\My Documents\LGXVRDmu.CSV") = true Then
rapi.CopyFileFromDevice1("\My Documents\LGXVRDmu.CSV",AppPath)
End If
End Sub
 

sunnyboyj

Member
I have made it wait 10 secs; same problem.
The PPC is connected before starting the program.
I am using activesync 4.5
Strange...
 
Last edited:

sunnyboyj

Member
I tried it but does not work. Then I cut my program in pieces:
I get the message 'connected'
I get the message 'file found' (so it can get the file when i start the program from desktop)
Then I get the error message, I think my syntax is just not correct:
Error is: Not a valid boolean (translated from Dutch error message).
I think I make an error copying from device (\My Documents\LGXVRDMU.CSV)
to my desktop: C:\downloads\

Form1.Show
rapi.New1
rapi.Connect
Sub Button2_Click
Msgbox ("Connected")

If rapi.DeviceFileExists("\My Documents\LGXVRDMU.CSV") = true Then
Msgbox("File Found")
rapi.CopyFileFromDevice2("\My Documents\LGXVRDMU.CSV","C:\downloads")
End If

End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This code copies a file from the device to the desktop (to the current path):
B4X:
Sub Globals
End Sub

Sub App_Start
    Form1.Show
    rapi.New1
    rapi.Connect
End Sub

Sub Rapi_Connected
    Msgbox("connected")
    If rapi.DeviceFileExists("\My Documents\a.exe") = true Then
        Msgbox("file exists")
        rapi.CopyFileFromDevice1("\My Documents\a.exe",AppPath)
    End If
End Sub
 

PSRC

Member
and use the same in device

and I want make the same but from on aplication on the device.

I execute the programe on the device and Iwant copy 1 file from the device to de c:\ directory???
 

PSRC

Member
ok

It is not possible with the RAPI library.
You can use the Network library to send the file.

Ok.
for exemple I have a secret file and on clik botton1 (using network) lib the file is copied from de device to the pc.
exemp:

FileCopy("pass.ert","c:\pass.ert") - but using the network

O I make this??????

sory mi inglish
 

Tex8503

Active Member
Licensed User
Longtime User
Sorry to dig up this old thread but this is relevent to a part of the project I'm working on.

I'm trying to synchronize a database between the PC and device. I know I can use RAPI on the desktop - which wouldn't be a problem, except it seems to lockup to application while the transfer is occurring.

Using the network library solved this problem and I was able to get a status of the file being sent per the 'FileTransfer' example - however, I can only seem to get the network library to be able to send files to the PC from the device and not the other way around.

Is there something I can do with RAPI Library to make it not lock the application or something I can do with the Network Library to make the transfer bi-directional?

Thanks!
 

agraham

Expert
Licensed User
Longtime User
Is there something I can do with RAPI Library to make it not lock the application
You could try running the transfer on a thread using my Threading library. If you are not familiar with threading read the help carefully to avoid coding in problems for yourself.

or something I can do with the Network Library to make the transfer bi-directional?
There shouldn't be any problem as you have a two-way communucation channel between the client and server. You just need to write the code for both the server and client to implement this.
 

Tex8503

Active Member
Licensed User
Longtime User
Agrham - Very interesting. I know OF threading, so I'd be interested in trying that with the RAPI - but it'd be easier for me if I can figure out how to get the damn networking library to work because it's already implemented and serves more of what I'm trying to do.

I basically broke apart the file transfer app into two separate applications and the PC acts as the server and the win mo device is the client. The FileTransfer example was pretty straight forward of how the client can initiate a file transfer to the server - but I still don't understand how the server could send a file back.

I thought of the possibility of re-arranging it so when I needed to send the file back to the win mo device, that I made the win mo device the server and the PC the client and just doing it that way. This has yet to work for me and I wondering its because the it can't get the hostname for the device using PPP_PEER - or if it has something to do with the win mo device / cradle not having USB Host.

Any suggestions? Am I even going in the right direction?
 

agraham

Expert
Licensed User
Longtime User
I don't understand your problem with the Network library. The server can send a file back in the same way the client sent one to the server. Once you have a client and a server connected you just write the code to do whatever you want.

PPP_PEER is only applicable to identify the desktop host of an ActiveSync connection.
 

Tex8503

Active Member
Licensed User
Longtime User
agraham - Can the server send data back in the same way? I haven't seen anything to suggest that...

It seems like the steps that happen are :
1)Server waits for client connection
2)Client connects using 'connect' and establishes bitstream
3)Server sees data is available.
4)client supplies opening bit, file size and file name then file
5)server receives in that order
6)Server reconciliation occurs (happens outside network library)
7)?

That's where I'm stuck. Can the server just write to the bitstream and have the client receive?
 

Zenerdiode

Active Member
Licensed User
Can the server send data back in the same way?

Yes. Because on the Server side; a Client and BinaryFile stream are also set up. Add these snippets to your SERVER code. You will need two timers too, one WFC(Wait For Connection) and one WFD(Wait For Data):

'Server' is a Network.dll Server object
'Client' is a Network.dll Client object
'Stream' is a BinaryFile.dll BinaryFile object

B4X:
Sub App_Start
   '...
   Server.New1(50000)
   Server.Start
   Client.New1
   TimerWFC.Enabled=True
   '...
End Sub

Sub TimerWFC_Tick
   If Server.Pending=True Then
      Client.Value=Server.Accept
      Stream.New1(Client.GetStream,False)
      TimerWFC.Enabled=False
      TimerWFD.Enabled=True
   End If      
End Sub

Sub TimerWFD_Tick
   If Client.DataAvailable=True Then
      Variable=Stream.ReadString
   End If
End Sub

To write anything back; use any of the BinaryFile.Writexxxx methods, such as

B4X:
...
Stream.WriteString("ASCII Text")
...
 

Tex8503

Active Member
Licensed User
Longtime User
Thanks Zenerdiode & agraham - took me about an hour to work through the issues I was having with the bi-directional transfer and while it's not pretty at the moment, it is working, which is more than I could say for it as of yesterday!

Thanks again for your help. If someone needs/wants it - I probably can rip the the code out of my app and setup something to demonstrate the bi-directional transfer.
 

Tex8503

Active Member
Licensed User
Longtime User
One last quick question: is it possible for multiple clients to connect to one server at the same time?
 

Tex8503

Active Member
Licensed User
Longtime User
Hey David,
Thanks for the tip. I'll take a look at your code and hopefully I can build it in!
 
Top