Listing available files and Downloading from FTP site
I'm working on a project where I need to download files from an FTP site for processing. Ideally, I'd like to get a list of the files into an array first, then skip over the files that begin with "AB" - but that would be a grace note.
The crux of my problem is the download portion.
I've been trying to use this code (set up to test code only), but keep getting a "Run-time error '429' ActiveX component can't create object" error.
[vba]
Sub ftptest()
Dim DidIGetIt As Boolean
DownloadFile "ftp://aValidFTPsite", "username", "password", _
"I want my sample file.txt", _
"C:\Temp\DOWNLOADED SampleFile.txt"
MsgBox DidIGetIt
End Sub
Function DownloadFile(ByVal HostName As String, _
ByVal UserName As String, _
ByVal Password As String, _
ByVal RemoteFileName As String, _
ByVal LocalFileName As String) As Boolean
Dim FTP as Inet
Set FTP = New Inet
With FTP
.Protocol = icFTP
.RemoteHost = HostName
.UserName = UserName
.Password = Password
.Execute .URL, "Get " + RemoteFileName + " " + LocalFileName
Do While .StillExecuting
DoEvents
Loop
DownloadFile = (.ResponseCode = 0)
End With
Set FTP = Nothing
End Function
[/vba]
I've got my references to Microsoft Internet Transfer Control 6.0 and ActiveX plugin set up, and no matter what I do, same problem. :dunno
Suggestions? Anyone? Beuhler? Beuhler?
PS: for some reason the VBA formatting thingie thinks its funny to stick colour references in lines 5 & 7 of the function, and muck about with the indents. Edit as needed, sorry & thanks.
In my case, error 429 was licensing error
I found the problem with my particular case...
One possible problem encountered while trying to run VBA macros involves the Microsoft Internet Transfer control (MSINET.OCX) ActiveX control to perform the ftp ?put? from source to target machine. MSINET.OCX is a licensed ActiveX control and requires a license for it to run on any machine. If MSINET.OCX is embedded into an executable VBA form interface using the toolbox at build-time, on a machine with an MSINET.OCX license, then the license for the Form instance of MSINET.OCX is built into the executable at that same time. It can then be distributed to any other machine, with OR WITHOUT a license, and will not run into licensing problems since the license is already built in.
Unfortunately, if you try to create (an Inet object) using MSINET.OCX programmatically by creating the object at runtime, not at build time, like this:
Dim ftp as Inet
ftp = New Inet
on a machine with no license for MSINET.OCX, runtime VBA attempts to find a license on the target machine and when it does not find it then a run-time an error (429: Cannot create object) is generated.
Especially for non-development machines, it is difficult to predict if the license exists. If the target machine has ever had Visual Basic 6.0 installed on it, or certain other developer packages, then those packages will already have installed the license on that machine, so when the Inet control is created at runtime a license is found and no error will occur, leading to confusion as to why sometimes the installation works, and sometimes it does not. The license is the key. If the target machine has no license, installing Visual Basic Express (free download from Microsoft) will install the license on that machine.
Lack of a license can be verified by trying to create the Internet Transfer control (on the target machine) on a Form using the toolbox. Make sure you have the proper reference checked in the "Tools/References" box (Microsoft Internet Transfer Control 6.0). Then try to add the control to a form. If the target machine is missing the license, a ?there is no license for this control?? message is generated. You can also look at the registry to see if the license is there. The XP Registery license entry looks like this:
HKEY_CLASSES_ROOT \ Licenses
78E1BDD1-9941-11cf-9756-00AA00C00908