Search code examples
actionscript-3apache-flexcurlair

cURL not work in Flex (as3)


I apologize in advance for the clumsy English) I have a problem with the launch of cURL in Flex. Here is my code:

private var process:NativeProcess;
private var file:File = new File();
private var uploadFile:File = new File();
private var username:String = "user";
private var password:String = "pass";
private var server:String = "ftp:\\--.---.---.---";

public var loadingBar:LoadingBar;

private function startUpload(event:Event):void
{
    loadingBar = LoadingBar(PopUpManager.createPopUp( this, LoadingBar, true));
    loadingBar.progressBar.source = process;
    PopUpManager.centerPopUp(loadingBar);

    file.nativePath = "C://curl.exe";
    uploadFile.nativePath = "C://001.mov";

    var arguments:Vector.<String> = new Vector.<String>();
    arguments.push("curl -T " + uploadFile.nativePath + " " + server  + " -u " + username + ":" + password);
    //arguments.push("curl http://isc.sans.org/infocon.txt");
    trace(arguments);

    var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
    nativeProcessStartupInfo.arguments = arguments;
    nativeProcessStartupInfo.executable = file;

    process = new NativeProcess();
    process.start(nativeProcessStartupInfo);

    process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onStandardErrorData);
    process.addEventListener(NativeProcessExitEvent.EXIT, onStandardOutputExit);

    process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);

    process.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onOutputIOError);
    process.addEventListener(IOErrorEvent.STANDARD_INPUT_IO_ERROR, onInputClose);
    process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR, onStandardIOError);
}

standardErrorData issues "% Total % Received % Xferd Average Speed Time Time Time Current

                       Dload  Upload   Total   Spent    Left  Speed

0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0" and then "curl: (6) Could not resolve host: curl -T C:\001.mov ftp:--.---.---.--- -u user". That is cut off before the colon, which is strange..

And if I use the commented line with the simplest command, instead of the one in before it, I get an error "curl: (1) Protocol curl http not supported or disabled in libcurl".

I do not understand is why so because of the command line the same commands work fine!


Solution

  • Your arguments vector is wrong, you should use a separate entry for each argument (unfortunately the Adobe Live Docs are not very clear about how this is supposed to look like), also there's no need to pass curl as an argument, the process already knows about the executable.

    var arguments:Vector.<String> = new Vector.<String>();
    arguments[0] = '-T';
    arguments[1] = uploadFile.nativePath;
    arguments[2] = server;
    arguments[3] = '-u';
    arguments[4] =  username + ':' + password;
    

    And make sure that

    curl -T uploadfile server -u user:passwd
    

    is actually the correct format. At least the examples in the manual are a little different, they look like

    curl -T uploadfile -u user:passwd server
    

    not sure whether this makes a difference.