0

I've created simple HTA-page

<input type="button" value="Run" onclick="run();">
<script>
function run() {
 var shell = new ActiveXObject('WScript.Shell');
 shell.run('cmd /c ftp -i -s:D:\ftp.bat',0,true);
}
</script>

And on my disk D created ftp.bat

open mydomain.com
username
password
cd /public_html
mput D:\filetobeuploaded.txt
quit

But when I run script on the HTA-page, file is not being uploaded to FTP.

If I run my BAT-file via cmd.exe, I succesfully connect to my FTP, but after mput command I get

500 I won't open a connection to 111.111.111.111 <only to 222.222.222.222>

425 No data connection

where 222.222.222.222 is my IP

As I can understand there are two separate problems:

1. I can't connect with FTP if I use

shell.run('cmd /c ftp -i -s:D:\ftp.bat',0,true);

2. I can't upload a file to FTP (no data connection)

14
  • 1
    Your .bat file is an ftp script. It is not a .BAT file. You should consider using ftp.exe instead of just ftp for the command. Depending on your current working directory it could see ftp.bat and think that is the ftp.exe command.
    – Squashman
    Commented Apr 16, 2018 at 20:49
  • Thanks! Now I can do something on FTP for example create a directory or rename a file if I use shell.run('cmd /c ftp.exe -s:ftp.bat',0,true) in my HTA-file. That has resolved the first problem. But I still can't upload a file
    – stckvrw
    Commented Apr 16, 2018 at 21:18
  • MPUT is normally used for multiple files whereas PUT is used for a single file. Also if the file name has spaces in it, then you need to quote the file name.
    – Squashman
    Commented Apr 16, 2018 at 21:21
  • 1
    Oh, it's Firewall. Ok, another question is: can I run the command with ftp.exe without changing firewall settings? Or is that only possible with 3rd party Windows FTP command-line clients as described by the link https://stackoverflow.com/a/28832663/3208225 ?
    – stckvrw
    Commented Apr 16, 2018 at 21:26
  • 1
    As said by the link stackoverflow.com/a/48488685/3208225 "one possibility is that the data-transfer connection is blocked by the firewall, whereas the control connection isn't"
    – stckvrw
    Commented Apr 16, 2018 at 22:12

0

Browse other questions tagged or ask your own question.