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)
ftp.exe
instead of justftp
for the command. Depending on your current working directory it could see ftp.bat and think that is the ftp.exe command.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 fileMPUT
is normally used for multiple files whereasPUT
is used for a single file. Also if the file name has spaces in it, then you need to quote the file name.