我编写了 VBA 代码,该代码根据 Excel 数据(Websphere MQ Define Job)为 IBM 主机创建一个包含作业代码的 .txt 文件。
如果能够通过 FTP 自动将此文件传输到主机,那就太酷了。此时我通过以下方式手动执行此操作:
(注释:LPAR = 主机名)
ftp <LPAR>
'user'
'password'
put 'dateiname'
它工作得很好。但我不知道如何将其转移到VBA代码中。我在这里发现了类似的问题,并发布了该解决方案:
Public Sub FtpSend()
Dim vPath As String
Dim vFile As String
Dim vFTPServ As String
Dim fNum As Long
vPath = ThisWorkbook.path
vFile = "path"
vFTPServ = "<LPAR>"
'Mounting file command for ftp.exe
fNum = FreeFile()
Open vPath & "\FtpComm.txt" For Output As #fNum
Print #1, "user *******" ' your login and password"
'Print #1, "cd TargetDir" 'change to dir on server
Print #1, "bin" ' bin or ascii file type to send
Print #1, "put " & vPath & "\" & vFile & " " & vFile ' upload local filename to server file
Print #1, "close" ' close connection
Print #1, "quit" ' Quit ftp program Close
Shell "ftp -n -i -g -s:" & vPath & "\FtpComm.txt " & vFTPServ, vbNormalNoFocus
SetAttr vPath & "\FtpComm.txt", vbNormal
Kill vPath & "\FtpComm.txt"
End Sub
我不确定我是否完全理解代码。我想我创建一个虚拟文件 FtpComm.txt,其中包含用户数据和内容,并使用该文件打开连接并发送数据。
它以某种方式起作用,直到这一点
*SetAttr vPath & "\FtpComm.txt", vbNormal*
我得到了错误
运行时错误:55 - 文件已打开。
此时已设置与 LPAR 的连接。但是“SetAttr...”有什么作用呢?这是输入完成的地方吗?我应该怎么办?