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)

Squashman
  • 13,649
  • 5
  • 27
  • 36
stckvrw
  • 1,689
  • 18
  • 42
  • 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 Apr 16 '18 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 Apr 16 '18 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 Apr 16 '18 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](https://stackoverflow.com/a/28832663/3208225) ? – stckvrw Apr 16 '18 at 21:26
  • Find it hard to believe you can create a directory or rename a file but you cannot upload a file. I don't know how a firewall could block some commands from FTP but not others. – Squashman Apr 16 '18 at 21:32
  • Now I see the file is being created on FTP but empty. While on my local disk D it has simple word `Text` inside – stckvrw Apr 16 '18 at 21:40
  • 1
    As said by the link https://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 Apr 16 '18 at 22:12
  • There's nothing you can configure in `ftp.exe` to make this working. So indeed, either setup the firewall or change your FTP client to some that supports passive mode. – Martin Prikryl Apr 17 '18 at 06:22
  • My original question is not a fully duplicate since it contains two separate questions and the first of them about running cmd commands with WScript.Shell – stckvrw Apr 17 '18 at 09:07
  • Well, that's another problem. You cannot ask two separate questions in one post. – Martin Prikryl Apr 17 '18 at 09:14
  • Ok. Btw, if I type `quote PASV` in ftp.exe, I get `227 Entering Passive Mode <...>`. Does it mean that ftp.exe of my Win7 has the passive mode? – stckvrw Apr 17 '18 at 09:18
  • No it does not mean anything. See https://stackoverflow.com/a/28833096/850848 – Martin Prikryl Apr 17 '18 at 09:32
  • I've allowed ftp.exe checking both options for public and private networks in my Windows Firewall, but I still get the error 425 No data connection. – stckvrw Jun 04 '18 at 19:10
  • Try using `curl` instead of `ftp`. `curl -u name:passwd ftp://yourdomain.com/full/path/to/file` [Reference](https://curl.haxx.se/docs/manual.html) – RizonBarns Apr 04 '20 at 16:37

0 Answers0