Advanced Search

Results 1 to 2 of 2

Thread: create and save .txt and batch and then run batch!

  1. #1
    Join Date
    Jan 2006
    Location
    Stephen Island Australia (QLD)
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question create and save .txt and batch and then run batch!

    Hello,
    I need a script that can write and save a text file with the extention .txt in a percific location. This location is c:/test.txt
    The text is irelevant but I need it to write something like

    ftp.domain.net.nz
    username
    password
    bye

    I then want the script to write and execute a batch script.
    Again the scripts not important but it would be something like

    ftp -s:c:/test.txt

    If someone can help thank you,
    Jacob Matysek

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Do you want this done client-side, or server-side?

    If client-side, not possible. Think about this logically. Can you imagine the chaos that would ensue if every site were able to write and execute batch scripts on your machine? Besides, the code wouldn't work on every machine even if it weren't a massive security risk. For example, machines running the bash shell wouldn't be able to make head nor tail of most of the constructs of DOS scripting -- bash has its own (far superior) scripting language.

    If server-side, it is possible, though the batch file isn't really needed. As you didn't specify a language, I'll write an example in PHP. Note that I've still used your idea of executing the external ftp.exe program, although PHP provides better ways of handling FTP resources.
    PHP Code:
    <?php
    if(!file_exists('C:\test.txt')) {
      
    $otter 'username' "\r\n" .
        
    'password' "\r\n" .
        
    'bye' "\r\n";
      
    $sealion fopen('C:\test.txt''w');
      
    fwrite($sealion$otter);
      
    fclose($sealion);
    }

    shell_exec('ftp -s C:\test.txt');
    ?>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •