gpt4 book ai didi

excel - 在 Windows Server 2012 R2 上从 VBA 调用批处理文件时出现奇怪的 FTP 行为

转载 作者:行者123 更新时间:2023-12-02 08:17:58 25 4
gpt4 key购买 nike

我有一个基本的 .bat 文件,它连接到 FTP 服务器,保存 CSV 文件列表,然后从 FTP 服务器下载所有 CSV 文件。我正在使用 VBA 调用 shell 来运行 .bat 文件。在我的工作笔记本电脑 (Windows 10) 上,一切运行正常,但如果我在 Windows Server 2012 R2 上运行它,.bat 文件会卡住,因为 FTP 服务器给出错误:

425 Can't open data connection for transfer of "/*.csv

我使用运行 FileZilla 服务器的 PC 进行测试,并且我还可以访问客户端的 FTP 服务器(不确定它们正在运行什么)。

这是我尝试过的:

在 Windows 10 和 Windows Server 2012 R2 上 - 禁用防火墙、64 位操作系统、Excel 2010 32 位。

在 Windows 10 笔记本电脑上:

  • 从命令提示符运行批处理文件工作正常
  • 从我的 VBA 代码使用的 Windows 运行窗口 (Winkey+R) 运行命令字符串,工作正常
  • 通过任务计划程序将批处理文件作为任务运行,效果很好
  • 运行调用 shell 来运行 .bat 文件的 VBA 子程序,工作正常

在 Windows Server 2012 R2 服务器上:

  • 从命令提示符运行批处理文件工作正常
  • 从我的 VBA 代码使用的 Windows 运行窗口 (Winkey+R) 运行命令字符串,工作正常
  • 通过任务计划程序将批处理文件作为任务运行,效果很好

问题:

  • 运行调用 shell 来运行 .bat 文件的 VBA 子程序时,批处理挂起。观察FTP服务器,批处理文件完成登录,然后显示错误425:

(000046)9/21/2015 10:36:11 AM - test (10.32.0.75)> 150 Opening data channel for directory listing of "/.csv"
(000046)9/21/2015 10:36:22 AM - test (10.32.0.75)> 425 Can't open data connection for transfer of "/
.csv"
(000046)9/21/2015 10:36:26 AM - test (10.32.0.75)> disconnected.

似乎只有当我尝试在 Server 2012 R2 计算机上使用 VBA 执行批处理文件时才会执行此操作。我不知所措......有什么想法吗?

批处理文件代码:

@echo off
REM Enter the username
echo user test> ftpcmd.dat

REM Enter the password
echo test>> ftpcmd.dat

REM Change the local computers' directory
echo lcd D:/XLRX/FTP/FTP_Tickets>> ftpcmd.dat

REM Get a list of the csv files we're about to copy
echo ls *.csv D:/XLRX/FTP/TESTCopiedCSV.txt>> ftpcmd.dat

REM Download all the csv files to the local directory
echo mget *.csv>> ftpcmd.dat

REM Remove the files we just downloaded from the FTP server

REM Close the connection
echo quit >> ftpcmd.dat

REM use -d for debugging, -i for preventing user interaction questions
ftp -i -n -s:ftpcmd.dat xxx.xxx.xxx.xxx

REM Clean Up
del ftpcmd.dat

REM Close the command window
EXIT

VBA 代码:

'Call the batch file to pull down the FTP tickets to the local server
sToday = Format(Now, "yyyymmdd_hhmm")

''-----------------------------------TEST CODE--------------------------------------''
''The following line works from the Windows RUN prompt on the EnerVest server:
''cmd /k "cd /d d:\xlrx\FTP && TESTGetFTPTickets.bat" >> D:\XLRX\FTP\FTP_Logs\TEST.log

If sTesting = "NO" Then
sFTPLogName = sToday & ".log" 'Sets the FTP log filename
sCMD = "cmd /k " & """cd /d D:\xlrx\FTP && GetFTPTickets.bat"""
Else
sFTPLogName = "TEST_" & sToday & ".log" 'Sets the FTP log filename if testing
sCMD = "cmd /k " & """cd /d D:\xlrx\FTP && TESTGetFTPTickets.bat"""
End If

sLog = ">> " & sFTPLogFolder & "\" & sFTPLogName
vArguments = Array(sCMD, sLog) 'New Code 9/20/2015

sShell = Join(vArguments, " ") 'Joins the above arguments into a string separated by " " (spaces)


'Call the Shell (command line) and use the sShell
Call Shell(sShell)

最佳答案

所以我也尝试使用“runas”选项......没有骰子。不幸的是,我不允许使用其他程序连接到服务器(尽管我喜欢 WinSCP)。我还尝试使用 vb 脚本调用批处理文件,但我在 FTP 服务器上得到了相同的行为。

我所做的解决方法是将批处理文件添加为任务计划程序中的计划任务,并让它每 5 分钟运行一次。这不是最好的解决方案,但在另一种方法能够实现之前,它必须有效。谢谢大家的帮助!

关于excel - 在 Windows Server 2012 R2 上从 VBA 调用批处理文件时出现奇怪的 FTP 行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32700620/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com