I'm in Windows 11. If you are currently on a LAN, then I recommend using this scheme:
ImportString[URLRead["sftp://12.12.12.57/home/user/42.jpg",
Authentication -> <|"Username" -> "user", "Password" -> "yourpass"|>]]
Or directly:
ImportString[URLFetch["sftp://12.12.12.57/home/user/42.jpg","Username" -> "user", "Password" -> "yourpass"]]
URLExecute["sftp://12.12.12.57/home/user/42.jpg",Authentication -> <|"Username" -> "user", "Password" -> "yourpass"|>]
1.)Or use the newest method in Acus' answer:
Import["!ssh -i \"C:/Users/myname/.ssh/key\" [email protected] cat /home/user/42.jpg","JPEG"]
2.)Or we can use RemoteEvaluate
+$DefaultRemoteKernel
(Personal most recommended):
RemoteEvaluate[KernelConfiguration[
"ssh://[email protected]/usr/local/bin/wolfram",
"SshIdentity" -> "C:/Users/myname/.ssh/pycharmkey2"], Import["42.jpg"]]
But note the kernel object describes a method for launching a kernel; it does not represent a persistent connection. We can get a persistent connection like following:
ker = KernelConfiguration[
"ssh://[email protected]/usr/local/bin/wolfram",
"SshIdentity" -> "C:/Users/myname/.ssh/pycharmkey2"];
launchker = First[LaunchKernels[ker]];
ParallelEvaluate[Import["42.jpg"], launchker]
3.)Or use RemoteRunProcess
+RemoteConnect
(Fastest):
ImportString[
RemoteRunProcess["12.12.12.57" , "cat 42.jpg", "StandardOutput",
Authentication -> <|"Username" -> "user", "Password" -> "yourpass"|>]]
4.)Or use wolframscript
:
ImportString[RemoteRunProcess["12.12.12.57",
"/usr/local/Wolfram/Mathematica/13.3/Executables/wolframscript \
-code 'Import[\"/home/user/42.jpg\"]' -format JPEG", "StandardOutput",
Authentication -> <|"Username" -> "user", "Password" -> "yourpass"|>]]
However, wolframscript
starts an mma kernel each time it runs, which is slow unless you use wolframscript -wstpserver
. But use wolframscript -wstpserver
, need to advance in the server startup SystemFiles/Links/wstpserver/wstpserver
. But if you try to use the wstpserver
to transfer large files, its efficiency is catastrophically slow.