I am trying to access a resource that is only available via SSH using a Mathematica notebook on my local computer, however I am not sure how I could tunnel a Mathematica command in such a way. I cannot run Mathematica on the remote resource.

The command I want to execute is


which is equivalent to running wget "http://server?parameters" in the terminal.

I tried to stack commands using the Run[] command, but it does not seem to work.

Run["sshpass -p "<> password <> " ssh " <> user "@" <> server;
"wget \"http://server?parameters\"";]

The return code I get while doing this is 0, but it does not seem like the command has actually been run on the remote server. I tried adding a "mkdir test" after the ssh command, and this is neither run on the remote server nor locally. However, if I remove the ssh command, the "mkdir test" successfully produces a folder in the Notebook directory.

Also, if I can run the wget command like this, how do I tunnel the file that is produced into Mathematica, instead of just taking the return code?


1 Answer 1


I have figured out a work-around, that requires Mathematica 11.3 or later. In this version, there is a new command, RemoteRun[], that works like Run[] but on a remote server.

If anyone knows a way of actually tunneling the Mathematica commands, and not just getting access to the remote Terminal, I would still appreciate it.

What worked for me is the following:

RemoteRun[server1, "wget \"http://server2?parameters\"",
    Authentication -> <|"Username" -> user, "Password" -> password|>]
RemoteRun[server1, "mv dataFile scrapFolder/",
    Authentication -> <|"Username" -> user, "Password" -> password|>]
data = Import[dataFile,"RAWjson"]

The variable data will then be the same as if you were to run

data = URLExecute["http://server1",parameters]

scpScript is a file containing the following code:

sshpass -p password scp user@server1:dirToScrapFolder/* ./

sshpass is a program that allows running ssh and scp without being prompted for the password. The downside of using this is that your password will be available in clear text in the file. The appropriate way would be to use keys, but that is not an option for me.

The Mathematica command RemoteRun[] will prompt you for the password if the Authentication part is not there, which is more secure.

Note: I was unable to run scp directly within Mathematica using the Run[] command, that is why I had to put it in a separate file.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.