AugustineWan
asked on
Use ftp within VBA
Hi:
I am attempting to do ftp operation within my VBA so that I could download files from the unix side. I read from several posts which recommend using the control "inet". My questions are:
- what is "inet" control ?
- where can I find it ?
- how do I put the "inet" control into my form ?
- sometimes it is called "inet", other times it is called "inet1". Which is right ?
Thanks
I am attempting to do ftp operation within my VBA so that I could download files from the unix side. I read from several posts which recommend using the control "inet". My questions are:
- what is "inet" control ?
- where can I find it ?
- how do I put the "inet" control into my form ?
- sometimes it is called "inet", other times it is called "inet1". Which is right ?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You dont need to use any control, just place code where ever you want to execute from and then create a text file with your ftp server info.
Private Declare Function URLDownloadToFile Lib "urlmon" _
Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Private Const ERROR_SUCCESS As Long = 0
Private Const BINDF_GETNEWESTVERSION As Long = &H10
Private Const INTERNET_FLAG_RELOAD As Long = &H80000000
Public Function DownloadFile(sSourceUrl As String, _
sLocalFile As String) As Boolean
DownloadFile = URLDownloadToFile(0&, _
sSourceUrl, _
sLocalFile, _
BINDF_GETNEWESTVERSION, _
0&) = ERROR_SUCCESS
End Function
Then simply call DownloadFile :
bResult = DownloadFile ( "ftp://ftp.site.com/path/file.ext", "c:\temp\file.ext" );
If you need to login on the ftp server with username and password, then modify the call like this :
bResult = DownloadFile ( "ftp://USERNAME:PASSWORD@ftp.site.com/path/file.ext", "c:\temp\file.ext" );
Alias "URLDownloadToFileA" _
(ByVal pCaller As Long, _
ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long
Private Const ERROR_SUCCESS As Long = 0
Private Const BINDF_GETNEWESTVERSION As Long = &H10
Private Const INTERNET_FLAG_RELOAD As Long = &H80000000
Public Function DownloadFile(sSourceUrl As String, _
sLocalFile As String) As Boolean
DownloadFile = URLDownloadToFile(0&, _
sSourceUrl, _
sLocalFile, _
BINDF_GETNEWESTVERSION, _
0&) = ERROR_SUCCESS
End Function
Then simply call DownloadFile :
bResult = DownloadFile ( "ftp://ftp.site.com/path/file.ext", "c:\temp\file.ext" );
If you need to login on the ftp server with username and password, then modify the call like this :
bResult = DownloadFile ( "ftp://USERNAME:PASSWORD@ftp.site.com/path/file.ext", "c:\temp\file.ext" );
ASKER
So, does it mean that it is not necessary to use the "inet" control to do the ftp ?