1

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.
4

1 回答 1

2

好的,我在一个 8 年前的帖子上找到了解决方案。(http://computer-programming-forum.com/61-wsh/813f07658378176c.htm

为了使用 Exec 方法从 ftp 命令获得完整的输出,必须将 -v 选项添加到 ftp 命令。奇迹般有效。

var shell = new ActiveXObject("WScript.Shell");
exec = shell.exec(cmd /c ftp -i -v -A -s:file.ftp host);
var output = exec.StdOut.ReadAll();
于 2013-08-30T09:35:19.670 回答