Question

I use an ActiveXObject in Javascript.

var shell = new ActiveXObject("WScript.Shell");

exec = shell.exec('cmd /c ftp -i -A -s:file.ftp host);

var output = exec.StdOut.ReadAll();

I'm getting the expected error "Could not create file" because the file already exists on the server. Everything's ok here. But the output doesn't display the error codes of ftp, while the Run method does (553 Could not create file).

I do not use Run method because the only output possible consists in redirecting the output into a file, on the client machine.

Trust me, I read a lot of websites (including Windows official descriptions of Run, Exec)

How can I get the error codes of ftp command using WScript.Shell.Exec command?

More info:

exec.StdOut.ReadAll() output ->

"bin
cd my_dir/
mput file_path file_path
Could not create file.
Could not create file.
quit"

output file from WScript.shell.run ->

ftp> bin
200 Switching to Binary mode.
ftp> cd my_dir/
250 Directory successfully changed.
ftp> mput file_path file_path
200 PORT command successful. Consider using PASV.
553 Could not create file.
200 PORT command successful. Consider using PASV.
553 Could not create file.
ftp> quit
221 Goodbye.
Was it helpful?

Solution

Ok, I found the solution on a 8 years old post. (http://computer-programming-forum.com/61-wsh/813f07658378176c.htm)

In order to get the complete output from ftp command using Exec method, the -v option has to be added to ftp command. Works like a charm.

var shell = new ActiveXObject("WScript.Shell");
exec = shell.exec(cmd /c ftp -i -v -A -s:file.ftp host);
var output = exec.StdOut.ReadAll();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top