Im trying to create VBA code to download a file to specific path from direct FTP link (asynchronously preferred). I only found code for making it work with http urls, but for FTP i get this error:
"Run-time error '-2146697210 (800c0006)': The system cannot locate the object specified"
For these first testing have not set username or password for the ftp-server.
My code which is working only for http is below:
Sub DownloadFile()
Dim myURL As String
myURL = "ftp://xxx.xxx.xxx.xxx/test.txt"
Dim WinHttpReq As Object
Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "GET", myURL, False, "username", "password"
WinHttpReq.send
myURL = WinHttpReq.responseBody
If WinHttpReq.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write WinHttpReq.responseBody
oStream.SaveToFile "C:\FTP\file.txt", 2 ' 1 = no overwrite, 2 = overwrite
oStream.Close
End If
End Sub
You will need to add a module to your project to get the FTP functionality. Sub FTPdownload has sample code. Taken from http://experts-exchange.com/Networking/Protocols/Q_23627204.html