我編寫了VBA代碼,該代碼根據Excel數據(Websphere MQ Define Job)爲IBM主機創建一個包含作業代碼的.txt文件。在VBA中使用FTP
有可能通過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*
在那裏,我得到的錯誤
Runtime-Error: 55 - File already opened.
到LPAR的連接設置在這一點上。但是「SetAttr ...」是做什麼的?這是輸入完成的地方嗎?我該怎麼辦?
您不妨看看http://wiki.lessthandot.com/index.php/FTP_in_Access – Fionnuala
您是否在shell中嘗試了命令?即鍵入shell'ftp -n -i -g -s: \ FtpComm.txt ?或一步一步? –
JMax