1

Is it possible to kick off MAGMI via the command line and have it automatically log into MAGMI (ie suppress the usual login prompt)

eg I'm invoking IE from a C# app and passing in:

http://localhost:1234/magmi/web/magmi_run.php?mode=update&profile=MyMAGMIProfile&engine=magmi_productimportengine:Magmi_ProductImportEngine&CSV:filename=../../data/upload/muk_000000045_price.csv

but it then comes up with the Login Prompt:

MAGMI login prompt

Can this prompt be avoided somehow?

[UPDATE]

From C# I've tried this:

...
            var str = "my password";
            var sc = new System.Security.SecureString();


            foreach (char c in str)
            {
                sc.AppendChar(c);
            }

            try
            {

                using (var process = Process.Start("IExplore.exe", "-nomerge " + completeURL, "maguser676", sc, ""))
                {
                    // Capture output...
                }
            }
            catch(Exception ex)
            {
            }
...

But raises an error saying that the user name or password is incorrect.

1 Answer 1

2

Now, this is not exactly the best place for a C#-related question, so I can't exactly tell whether this works for you in your environment but one approach can be to specify the username and password together with the URL like so:

var completeURL = "http://maguser676:mypassword@localhost:1234/magmi/web/magmi_run.php?mode=update&profile=MyMAGMIProfile&engine=magmi_productimportengine:Magmi_ProductImportEngine&CSV:filename=../../data/upload/muk_000000045_price.csv";

Second option would be to comment a part of the authentication behavior and restrict the access to MAGMI by an IP address without further authentication (obviously, you should not do this if the C#-application is executed by a machine without a static IP address and/or there are other reasons why the IP address is not to be rated secure e.g. due to the networks topology it is assigned to):

magmi/.htaccess (create this new file)

# Allow access to MAGMI GUI by the following IP address only
<RequireAll>
    Require ip 123.234.123.234
</RequireAll>

magmi/web/security.php (comment the if/else condition) Note: There may be several places from where you could prevent MAGMI from asking for authentication, but that one was the first that came in my mind:

<?php
require_once(dirname(dirname(__FILE__))."/inc/magmi_auth.php");
function authenticate($username="",$password=""){

    $auth = new Magmi_Auth($username,$password);

    return $auth->authenticate();
}

// WWW-Auth disabled since we authenticate based on the IP address only.
/*if (!isset($_SERVER['PHP_AUTH_USER'])) {
    header('WWW-Authenticate:Basic realm="Magmi"');
    header('HTTP/1.0 401 Unauthorized');
    echo 'You must be logged in to use Magmi';
    die();
} else {
    if (!authenticate($_SERVER['PHP_AUTH_USER'],$_SERVER['PHP_AUTH_PW'])){
        header('WWW-Authenticate: Basic realm="Magmi"');
        header('HTTP/1.0 401 Unauthorized');
        echo 'You must be logged in to use Magmi';
        die();
    }

}*/

Ultimately, as a third option you could execute MAGMI by a cron job on the webserver (or by creating a Magento module that will schedule the execution of MAGMI on a regular basis) and just push the CSV to the import directory (side node: MAGMI could even connect to a remote database server e.g. via ODBC to get its data). This however might depend on your actual requirement and would require rather fundamental questions such as why there is a C#-application needed to execute a MAGMI import profile (which for sure can have its very own valid reason).

1
  • it's working for me i was just miss the user name and password to add in url Thanks Commented Jan 10, 2018 at 7:37

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.