Take the 2-minute tour ×
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", "####@understars.org:temp.understars.org"]

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
1  
Have you seen this question: mathematica.stackexchange.com/questions/3097/… ? –  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 ####@understars.org:temp.understars.org","commands to execute"] –  celtschk Aug 31 '12 at 12:22
    
Also note that RunThrough interprets the produced output of the external command as Mathematica expression, which probably isn't quite what you want here. For example, RunThrough["echo 1+1",""] gives 2. –  celtschk Aug 31 '12 at 12:28

1 Answer 1

up vote 6 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 these lines: (tested on Windows and Linux, not on Mac). It should all work on Mathematica 7, 8 or 9:

(* getting the package installer *)
Import["http://packageinstaller.googlecode.com/hg/PackageInstaller/PackageInstaller.m"];
(* installint MSFTP` into $UserBaseDirectory/Application easily by: *)
PackageInstaller`InstallPackage["http://msftp.googlecode.com/hg/MSFTP.zip"];
(* load the package *)
Needs["MSFTP`"];
(* open the example notebook *)
NotebookOpen[
  FileNameJoin[{ParentDirectory@DirectoryName[FindFile["MSFTP`"]], 
    "MSFTP.nb"}]];

Then you can do things like

MSFTPPut[NotebookDirectory[] // ParentDirectory, "MSFTP2", "Password"->"secret",
  "UserName" -> "testuser", "HostName" -> "testserver.example.com"]]

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

PassEncode["secret"]

gives

   {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

 
discard

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.