Utilizando FTP en VBA
Escribí un código VBA que crea un archivo .txt con Job-Code para un host de IBM basado en datos de Excel (Websphere MQ Define Job).
Sería genial tener la posibilidad de transferir este archivo al host automáticamente a través de FTP. En este punto, hago esto manualmente a través de:
(comentario: LPAR = Nombre de host)
ftp <LPAR>
'user'
'password'
put 'dateiname'
Funciona bastante bien. Pero no sé cómo transferir esto al código VBA. Encontré una pregunta similar aquí y allá, esta solución fue publicada:
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
No estoy seguro si entiendo el código por completo. Creo que creo un archivo ficticio, FtpComm.txt, con los datos del usuario y el contenido, y uso este archivo para abrir la conexión y enviar los datos.
Funciona, de alguna manera, hasta el punto
*SetAttr vPath & "\FtpComm.txt", vbNormal*
Ahí me sale el error
Runtime-Error: 55 - Archivo ya abierto.
La conexión a LPAR se establece en este punto. Pero, ¿qué hace "SetAttr ..."? ¿Es este el punto donde se realiza la entrada? ¿Qué tengo que hacer