我创建了一个脚本,用于从FTP服务器下载一个文件,使用VBA启动该脚本。我可以连接到服务器并导航到正确的目录,但是当我得到文件时,我得到了消息:
500端口命令无效
我已经尽可能地修改了代码,但是我对端口或FTP还不太了解,不知道我需要修改什么。
VBA代码:
Dim FTPcommand As String
Dim wsh As Object
FTPcommand = "ftp -n -s:" & Chr(34) & "C:\path\to\FTP_commands.txt" & Chr(34)
Set wsh = CreateObject("WScript.Shell")
wsh.Run FTPcommand, 5, True剧本:
open ftp.blahblahbah.bl
user username password
lcd C:\Users\me\Documents\location
cd /specific location/
get "file.xlsx"我希望该文件能够下载,但获得以下消息(在脚本登录并成功导航到文件路径之后):
ftp>开放式ftp.address.com 连接到ftp.address.com 220欢迎来到address.com ftp>用户用户名密码 ->用户用户名 331用户用户名,密码 ->通过密码 230密码好,用户登录 ftp lcd C:\User\joe\Document 本地目录现在是C:\Users\joe\Document。 ftp> cd /location/ ->CWD /location/ 250更改目录确定 ftp获取"file.xlsx“ -> 192.168.1.121.242.113港 500端口命令无效 RETR file.xlsx 425无法打开数据连接
发布于 2019-08-28 05:22:04
-> 192.168.1.121.242.113港 500端口命令无效
看起来,ftp正在向另一个网络中的FTP服务器发送内部IP地址。服务器无法连接到该IP地址。我认为没有办法用ftp来解决这个问题。网络的防火墙/NAT可以通过在PORT命令中转换IP地址来解决这个问题。
或者您需要使用不同的FTP客户端,它支持FTP被动模式。
您可以使用WinSCP FTP客户端。有一个脚本到WinSCP。
以下WinSCP代码等效于您的代码:
Dim FTPcommand As String
Dim wsh As Object
FTPcommand = """C:\Path\To\winscp.com"" /ini=nul /script=""C:\Path\To\FTP_commands.txt"""
Set wsh = CreateObject("WScript.Shell")
wsh.Run FTPcommand, 5, True剧本:
open ftp://username:password@ftp.blahblahbah.bl/
lcd C:\Users\me\Documents\location
cd /specific location/
get "file.xlsx"
exit(我是WinSCP的作者)
https://stackoverflow.com/questions/57677006
复制相似问题