Execute Batch File

Discussion in 'PHP' started by mukeshgulia, Jul 12, 2009.

  1. #1
    Hi,
    I tried to run a batch file via PHP functions exec()/passthru()/system()
    Basically my batch file picks all the xml files from the current location and ftp them to a server.

    None of the functions worked for me. Please help.
    All files are located at the configured IIS folder Test IIS

    batch file 'ftp.bat' contents are:
    cd c:\windows\system32
    ftp -s:c:\TestIIS\ftp.txt 128.91.16.203
    Code (markup):
    'ftp.txt' file contains:
    ora10g
    ora10g
    cd /home/oracle/dit/XMLDIR
    prompt off
    lcd c:\TestIIS
    bin
    mput *.xml
    bye
    Code (markup):
    I tried the following code:.
    <?php
    if(isset($_POST['submit']))
    {
    echo exec('ftp.bat');
    echo "Done!";
    } else {
    // display the form
    ?>
    <form action="" method="post">
    <input type="submit" name="submit" value="DO IT!">
    </form>
    <?php
    }
    ?>
    
    Code (markup):
    I am unable to run this file successfully.
    Please help
     
    mukeshgulia, Jul 12, 2009 IP
  2. darren884

    darren884 Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You need to do this another way. Parse the XML file and then use PHP built in FTP functions to do it. Of course this script is not going to work because usually you need root permissions (admin on windows) to execute files like this and that would just be a very bad security hole especially in this situation. Security is the issue here, I hope you understand.
     
    darren884, Jul 12, 2009 IP
  3. mukeshgulia

    mukeshgulia Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes sir, I do understand security issues. This content wud be assessable to only concerned person.
    Problem is there would be thousands of xml files. how to make a loop to pick xml files one by one and parse them.
    FTP functions can work on one XML file only. Correct me if I am wrong. Also, Please provide a sample code to parse XML and ftp them using inbuild functions. It would be very greatful.
    Thanks.
     
    mukeshgulia, Jul 12, 2009 IP
  4. mukeshgulia

    mukeshgulia Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    please help. anybody!!!!!!
     
    mukeshgulia, Jul 13, 2009 IP
  5. Goramba

    Goramba Peon

    Messages:
    128
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Goramba, Jul 13, 2009 IP