Using rapi from desktop to copy file from device to desktop

Discussion in 'Questions (Windows Mobile)' started by sunnyboyj, Jan 7, 2008.

  1. sunnyboyj

    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
    t = Now '3 seconds timeout.
    Do Until rapi.IsConnected = true
    If (Now - t)/cTicksPerSecond > 3 Then
    Msgbox("Cannot connect to device.")
    End If
    If rapi.DeviceFileExists("\My Documents\LGXVRDmu.CSV") = true Then
    rapi.CopyFileFromDevice1("\My Documents\LGXVRDmu.CSV",AppPath)
    End If
    End Sub
  2. Erel

    Erel Administrator Staff Member Licensed User

    Did you connect the device before running the program? (you should)
    Try to increase the time limit.

    What is your ActiveSync version?
  3. sunnyboyj

    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
    Last edited: Jan 8, 2008
  4. Erel

    Erel Administrator Staff Member Licensed User

    You could try to uninstall and reinstall Activesync.
    Another option is to use a different approach and send the file using Network library (based on Activesync connection).
  5. sunnyboyj

    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\

    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
  6. Erel

    Erel Administrator Staff Member Licensed User

    This code copies a file from the device to the desktop (to the current path):
    Sub Globals
    End Sub

    Sub App_Start
    End Sub

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

    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???
  8. Erel

    Erel Administrator Staff Member Licensed User

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

    PSRC Member


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

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

    O I make this??????

    sory mi inglish
  10. Erel

    Erel Administrator Staff Member Licensed User

  11. Tex8503

    Tex8503 Active Member Licensed 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?

  12. agraham

    agraham Expert Licensed User

    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.

    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.
  13. Tex8503

    Tex8503 Active Member Licensed 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?
  14. agraham

    agraham Expert Licensed 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.
  15. Tex8503

    Tex8503 Active Member Licensed 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)

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

    Zenerdiode Active Member Licensed User

    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

    Sub App_Start
    End Sub

    Sub TimerWFC_Tick
    If Server.Pending=True Then
    End If      
    End Sub

    Sub TimerWFD_Tick
    If Client.DataAvailable=True Then
    End If
    End Sub
    To write anything back; use any of the BinaryFile.Writexxxx methods, such as

    "ASCII Text")
  17. Tex8503

    Tex8503 Active Member Licensed 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.
  18. Tex8503

    Tex8503 Active Member Licensed User

    One last quick question: is it possible for multiple clients to connect to one server at the same time?
  19. derez

    derez Expert Licensed User

  20. Tex8503

    Tex8503 Active Member Licensed User

    Hey David,
    Thanks for the tip. I'll take a look at your code and hopefully I can build it in!
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice