Julia as a bridge between windows and raspberry pi

Hello everyone,

I’m trying to create project that runs in raspberry pi and windows and I want that Julia works as a bridge between both platforms.
I will try to explain.
I run Julia in my raspberry pi in order to process some data and create some particular files. This part is ok.
Now, I want to from my windows machine get those files to be treated using for that julia.

I already created an ssh connection between raspberry and windows but what i need, and what i don’t know how to do, is a piece of code in julia that allows me to go to the location of my files in my raspberry pi and copy them to a specific location in my windows machine.

Do you have any idea how this can be done?
Thanks in advance.

1 Like

OpenSSH for Windows

It sounds like you have an ssh connection setup, so I think you continue to use that. The key command line tool to use is either sftp or scp. I recommend scp.

Installing OpenSSH for Windows is pretty easy. Microsoft has OpenSSH as an Optional Feature of Windows now:

Once you have that you can run scp from julia as follows.

julia> run(`scp`)
usage: scp [-346BCpqrTv] [-c cipher] [-F ssh_config] [-i identity_file]
            [-J destination] [-l limit] [-o ssh_option] [-P port]
            [-S program] source ... target
ERROR: failed process: Process(`scp`, ProcessExited(1)) [1]

Above you can see scp printed some help messages. What you want to do is something like

run(`scp username@raspberry_pi.host.name:/path/on/rpi C:\\path\\to\\local\\windows\\folder`)


If you wanted to do this on hard mode, you could use LibSSH2_jll and call the libssh2 API. Here’s an example for the C function libssh2_version:

julia> using Pkg

julia> pkg"activate --temp"
  Activating new project at `C:\Users\username\AppData\Local\Temp\jl_0N2fUl`

julia> pkg"add LibSSH2_jll"
    Updating registry at `C:\Users\kittisopikulm\.julia\registries\General.toml`
   Resolving package versions...
    Updating `C:\Users\username\AppData\Local\Temp\jl_0N2fUl\Project.toml`
  [29816b5a] + LibSSH2_jll v1.10.2+0
    Updating `C:\Users\username\AppData\Local\Temp\jl_0N2fUl\Manifest.toml`
  [56f22d72] + Artifacts
  [8f399da3] + Libdl
  [29816b5a] + LibSSH2_jll v1.10.2+0
  [c8ffd9c3] + MbedTLS_jll v2.28.2+0

julia> using LibSSH2_jll

julia> version = ccall((:libssh2_version,LibSSH2_jll.libssh2_path), Cstring, (Cint,), 0)

julia> unsafe_string(version)

See the following documentation about how to call C from Julia.


1 Like

Hello @mkitti ,
I tryied the first option but Im getting the following error:

What am I doing wrong?
Thank you in advance.

Note how I have \\ instead of \. This is because Julia regards the \ as an escape character.

Alternatively, you might consider using raw strings.

raw_str_path = raw"C:\Users\Username\Documents"
run(`scp rduarte@raspberrypi:/media $raw_str_path`)

Hi @mkitti
I just tried but the result remains

Do you have any idea why?

It looks like you have a space in your folder name. This is a common cause for headaches and why I usually avoid spaces in file or directory names.

Try putting quotes around the paths.

Scp seems to think C is a host. I’m not sure why.

Can you confirm where you got ssh and scp from?

Hello @mkitti
I tried already without space and I get the same error.
To do: ssh my.raspberypi.ip.adress -l rduarte
I installed windows server through the following link:

For the scp I just typed the lines you wrote in the first post.
I’m really new on this, sorry if I miss some point.

The problem is that scp is confused by C:\.... It thinks anything before the colon should be a hostname and it cannot find a host called C.

You might need to use quotes or d
or some alternative way to provide the path.

Try some variants of the following:

  • scp rduarte@rapsberrypi:/some/path "C:\\User\\Duarte\\Desktop"
  • scp rduarte@rapsberrypi:/some/path "C:/User/Duarte/Desktop"
  • scp rduarte@rapsberrypi:/some/path "C/User/Duarte/Desktop"

Maybe cd first and then try the following. The . means to copy it to the current directory.

run(`scp rduarte@rapsberrypi:/some/path .`)

If you want to have a shared filesystem between a R PI (Linux) and Windows you have many choices.
A very easy one is to use MobaXterm which has a built in graphical SFTP browser/transport utility

Other choices are creating an NFS share on the RPI and mounting that on Windows
Or you could use a CIFS share on either Windows or RPI and use Samba on RPI

You say you have an ssh connection availalbe. There are ssh based filesystems
SSHFS: How to Mount Remote File Systems Over SSH | phoenixNAP KB.

Please contact me if you want some help setting this up.

Thank you @johnh but this is not the kind of solution i’m looking for.
I what to pass files between raspberry and windows. Let’s say, when using windows, through an ssh connection I want to open julia in raspberrypi and then copy some files to my windows.
Thanks anyway.

Hello @mkitti,
Still not working.
Can you describe me what should I do to have a succefull scp connection between both os?
Maybe is there the error.
Thank you

@rduarte That is exactly how the SFTP browser works in MobaXterm.
Please install MobaXterm on your Windows laptop and try it.

What’s the current error? Is it changing at all?

I would expect this to create a different error than the ones you have been encountering.

run(`scp rduarte@rapsberrypi:/some/path .`)

Have you tried opening up Cmd.exe or Powershell.exe and executing the commands directly there?

Hello @mkitti
The error I getting now is:

Is it important that this should happen from inside Julia, and from running a single command, perhaps inside a larger workflow? Or is it okay if the file transfer happens in the end, possibly requiring user input, more like a seperate step?

Hello @TheLateKronos
Yes, I need that happens from inside Julia.

1 Like

I would first try do debug this outside of julia. You say that you have ssh working. I assume that is from powershell or something like that. So go to powershell:

ssh <username>@<raspberrypi>

should get you into the raspberry pi (with <username> and <raspberrypi> of course replaced by the appropriate values). There running touch somefile will create a file on your pi. Exiting the raspberry pi, you should then be able to do:

scp <username>@<raspberrypi>:somefile ./

If not then there is something wrong. If it works, but asks for a password, you will probably first have to set up loging in using keys; as typing in passwords from julia will be impractical. For that see, for example, How To Configure SSH Key-Based Authentication on a Linux Server | DigitalOcean. If that works, then running the same commands from julia should also work.

1 Like

It probably is that directory does not exist. Specifically, are you sure the path is “User” not “Users” with an “s”?

Hello @djvanderlaan
I was able to connect to raspberry and create the “somefile” on it. However, when I try to do the scp (outside julia) i get the following message:
scp: .:not a regular file