The error is E_ACCESSDENIED. Are you, by any chance, calling
URLDownloadToFile from a service running under SYSTEM account?
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
Dim RetCode As Long
RetCode = URLDownloadToFile(0,
"ftp://username:pass...@ftp.ftpurl.com/File.txt", "C:\Test\File.txt",
0, 0)
If Not (RetCode = 0) Then
MsgBox "Boom" 'The message box is displayed. RetCode = -2147024891
End If
Do you have rights to write to this file? In Explorer, can you create a
file in this directory?
You should be able to create a COM object that implements
IBindStatusCallback and IAuthenticate, and pass it as the last
parameter. You can then supply user name and password via
IAuthenticate::Authenticate.
Another thing to try is InternetSetOption(NULL,
INTERNET_OPTION_PROXY_USERNAME) and INTERNET_OPTION_PROXY_PASSWORD. I'm
not sure if this works.
I am also getting error from UrlDownloadToFile(). But, my scenario and error
code are different. It fails when executed from behind proxy and under
SYSTEM account. It works fine if I either use direct connection or run under
a user account. I am making following call:
URLDownloadToFile(NULL, wszURL, wszFullpath, 0, NULL);
I have a service that runs under SYSTEM credentials. This service launches a
program, say, DownloadMyFile.exe that downloads a file using above call.
This download works.
Then I connect my machine to proxy and specify the proxy thru IE options.
After this URLDownloadToFile starts giving INET_E_RESOURCE_NOT_FOUND
(-2146697211) error.
Now when I double click on DownloadMyFile.exe, which makes it run under user
credentials, it successfully works, even from behind proxy.
I tried this on Vista/Win7/XP and found same behavior.
Any clues?
You do this while IE is running under which account? My guess is, IE settings are per user so SYSTEM never sees your settings and doesn't know it's supposed to use a proxy.