Log in

View Full Version : create and save .txt and batch and then run batch!



hakopa
03-01-2006, 05:27 AM
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

Twey
03-01-2006, 04:31 PM
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 (http://www.gnu.org/software/bash/bash.html) 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
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');
?>