1

我无法从访问中运行 .bat 文件。.bat 文件已创建,日志已创建(其中没有任何内容),当我在 Windows 资源管理器中单击 .bat 文件时将运行它,但我无法使用 .RUN 命令运行它。

sFTP = "ftp -s:FTPCMD.TXT > Z:\Recon\FTPUtilSrc\ftprslt.txt"
Open sFileName For Output As #2
Print #2, sFTP
'Print #2, "EXIT"
Close #2
oShell.Run sFileName, 0, True    

编辑:

sFileName = "Z:\Recon\FTPUtilSrc\MYFTP.BAT"
sFTP = "ftp -s:FTPCMD.TXT > Z:\Recon\FTPUtilSrc\ftprslt.txt"
Open sFileName For Output As #2
Print #2, sFTP
Print #2, "EXIT"
Close #2
oShell.run sFileName, 0, True
4

2 回答 2

1

试试这个:

Dim cmd_str As String
cmd_str = "cmd.exe /C ftp -s:FTPCMD.TXT > Z:\Recon\FTPUtilSrc\ftprslt.txt"
Call Shell(cmd_str, vbNormalFocus)
于 2013-11-13T20:43:19.820 回答
0

尝试更改几件事以查看发生了什么:

sFileName = "Z:\Recon\FTPUtilSrc\MYFTP.BAT"
sFTP = "ftp -s:FTPCMD.TXT > Z:\Recon\FTPUtilSrc\ftprslt.txt"
Open sFileName For Output As #2
Print #2, sFTP
Print #2, "PAUSE" 'PAUSE forces the command prompt window to stay open.  This temporarily allows you to see if there are any issues with the ftp statment.
Close #2
oShell.run sFileName, 0, True '3 is "Activates the window and displays it as a maximized window." according to msdn.  This will allow you to see the execution of the ftp statment

查看这些更改是否有助于您识别问题,以便您可以将其更改回来。顺便说一句,我通过运行以下代码测试了代码,它按预期工作,这让我相信这是 ftp 命令的问题。

Public Sub TestBat()
    Set oShell = CreateObject("WScript.Shell")
    sFileName = "C:\Temp\MYECHO.bat" '"Z:\Recon\FTPUtilSrc\MYFTP.BAT"
    sFTP = "echo ""hi"" > C:\Temp\test.txt" '"ftp -s:FTPCMD.TXT > Z:\Recon\FTPUtilSrc\ftprslt.txt"
    Open sFileName For Output As #2
    Print #2, sFTP
    Print #2, "PAUSE"
    Close #2
    oShell.Run sFileName, 3, True
End Sub
于 2013-11-13T22:06:27.920 回答