Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have MMA-generated html and would like to automate uploading to a named directory to a web host via SFTP or HTTP POST, ideally without creating local temp files. The closest question I could find on MMA.SE is this question which doesn't really address this issue.

Based on this "minimal http upload gci" in Python, and HTTP Request-Authentication flow-chart, it seems that uploading by FTP may be relatively easier. Sjoerd C. de Vries suggested this question may answer the POST part.

Others have found FTP in non-interactive mode to be difficult. But one would think authentication, put and closing the session in interactive mode could be managed within MMA.

However, Run is not meant to capture output from the external program. From the sparse documentation, I think RunThrough is meant to capture external program output, but I can only manage to capture an exit condition code:

RunThrough["sftp", ""]

Doesn't output to the front end, but does set the Out[] to 256.

So how can an interactive FTP session be automated?

(Note I've tagged this "html" as well since ultimately that is what I want to export.)

share|improve this question
Have you seen this question:… ? –  Sjoerd C. de Vries Aug 29 '12 at 21:04
@SjoerdC.deVries, thanks, no I had not seen that. But reading it I am confused as to how to apply the answers to my situation. Do you recommend I edit my Q to just focus on FTP? –  alancalvitti Aug 29 '12 at 21:11
It seems that the POST part of your question has been handled. Since I haven't worked with the solutions intensively I don't know whether they're sufficient for your case. If they are, I suggest removing the POST part from your question. –  Sjoerd C. de Vries Aug 29 '12 at 21:15
sftp wants its destination as command line argument, not as standard input. Maybe you'll have more success with RunThrough["sftp","commands to execute"] –  celtschk Aug 31 '12 at 12:22
The title should be changed to say "SFTP" instead of "FTP". –  Joel Klein Feb 4 '13 at 16:35

1 Answer 1

up vote 12 down vote accepted

Using a slightly modified version of vngx-jsch (source included), an open-source implementation of jsch, and JLink and a small but efficient Mathematica package this is now easily possible. All code can be browsed here, and most simply be installed by executing this twitterable line: (tested on Windows, Linux and Mac, but not on the Raspberry Pi). It should all work on Mathematica 7, 8, 9 and 10 (though I did not test the new version on Mathematica 7 and 8).

Get @ ""

This loads from Github my updated MathematicaPackageInstall function in order to automatically install the package from Github to your local $UserBaseDirectory/Applications folder. At the end of the installation process (give it half a minute) a notebook MSFTP.nb opens with some examples in it.

If you have set up your sftp (ssh) server (any Linux box will do) and opened port 22 on your firewall you can do things like

MSFTPPut[NotebookDirectory[], "test", "Password"->"secret",
  "UserName" -> "testuser", "HostName" -> ""]]

There is also a MSFTPGet function for getting files and directories.

As a goodie I added PassEncode, so you can encode your password on your $MachineID, i.e., on my machine



   {40, 42, 33, 49, 72, 33, 42, 41, 57, 50, 125, 10, 64, 120, 122, 106, \
124, 63, 34, 77, 113, 55, 94, 57, 113, 110, 89, 70}

which can be used insted of "secret" in MSFTPPut or MSFTPGet. So the advantage is you don't have to save clear-text passwords in your notebook, but some $MachineID dependent encryption of it.

share|improve this answer
Tks Rolf!.. Tested and approved. I'll start to use it in some automatic file exchanges! –  Murta Apr 11 '13 at 0:54

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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