【发布时间】:2013-08-29 13:24:34
【问题描述】:
我在 Javascript 中使用 ActiveXObject。
var shell = new ActiveXObject("WScript.Shell");
exec = shell.exec('cmd /c ftp -i -A -s:file.ftp host);
var output = exec.StdOut.ReadAll();
我收到预期错误“无法创建文件”,因为该文件已存在于服务器上。这里一切正常。但是输出不显示ftp的错误代码,而Run方法却显示(553无法创建文件)。
我不使用 Run 方法,因为唯一可能的输出是将输出重定向到客户端计算机上的文件中。
相信我,我阅读了很多网站(包括 Windows 官方对 Run、Exec 的描述)
如何使用 WScript.Shell.Exec 命令获取 ftp 命令的错误码?
更多信息:
exec.StdOut.ReadAll() 输出 ->
"bin
cd my_dir/
mput file_path file_path
Could not create file.
Could not create file.
quit"
来自 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.
【问题讨论】:
-
WshScriptExec.stdErr无法解决问题? -
我使用了
exec.StdErr.ReadAll(),遗憾的是,这并没有按预期工作。这会在 ftp 提示出现之前显示“登录成功”消息。
标签: javascript windows ftp cmd wsh