Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with inet control 1

Status
Not open for further replies.

cyberwolf14

Programmer
Aug 27, 2001
65
BE
Hello,

I use this code to download a file from a server.
Code:
Inet1.Protocol = icFTP
Inet1.URL = "ftp.server.com"
Inet1.UserName = "username"
Inet1.Password = "*********"
Inet1.Execute , "GET /downl/file.exe C:\test.exe"
Everything works fine until I use a [SPATIE] in the name of the file I want to download.
Code:
Inet1.Protocol = icFTP
Inet1.URL = "ftp.server.com"
Inet1.UserName = "username"
Inet1.Password = "*********"
Inet1.Execute , "GET /downl/file 2.exe C:\test.exe"
This doesn't work

What do I need to do so I can download a file with a [SPATIE]?
 
The Inet is very limited in what it can do. It only handles the basics.

On the other hand, the WININET API contains a much richer functionality. I think I would use direct API calls into this library.
Good Luck
------------
Select * from Users where Clue > 0
0 rows returned
 
And can you give me an example how I download a file with the WININET API??
 
Const FILENAME_DEFIFNITION = 0
Const INTERNET_OPEN_TYPE_DIRECT = 1
Const INTERNET_SERVICE_FTP = 1
Const FTP_TRANSFER_TYPE_ASCII = &H1

Global gInt_Counter As Integer
Global gInt_TimeOut As Integer
Global mCol_Requests As New Collection
Global mCol_Responses As New Collection

Global gInt_LoopCount_Arr(999) As Integer

'----------------------------------------------------------

Public Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long

Public Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" (ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long

Public Declare Function FtpPutFile Lib "wininet.dll" Alias "FtpPutFileA" (ByVal hFtpSession As Long, ByVal lpszLocalFile As String, ByVal lpszRemoteFile As String, ByVal dwFlags As Long, ByVal dwContext As Long) As Integer

Public Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer

'---------------------------------------------------------

Private Function FTP_Get_Transfer(rStr_FromFile As String, rStr_ToFile As String) As Boolean

Dim lLng_OpenHand As Long
Dim lLng_ConnHand As Long
Dim lBol_GetOK As Integer
Dim lBol_TranOK As Boolean

lBol_TranOK = False
lLng_OpenHand = InternetOpen(&quot;<Agent Name-Your Choice>&quot;, INTERNET_OPEN_TYPE_DIRECT, &quot;&quot;, &quot;&quot;, 0)
If (lLng_OpenHand > 0) Then
lLng_ConnHand = InternetConnect(lLng_OpenHand, &quot;<FTP Address Goes Here>&quot;, 0, &quot;<User ID>&quot;, &quot;<Password>&quot;, INTERNET_SERVICE_FTP, 0, 0)
If (lLng_ConnHand > 0) Then
lBol_GetOK = FtpGetFile(lLng_ConnHand, rStr_FromFile, rStr_ToFile, False, 0, FTP_TRANSFER_TYPE_ASCII, 0)
If (lBol_GetOK <> 0) Then
lBol_TranOK = True
End If
InternetCloseHandle (lLng_ConnHand)
Else
MsgBox &quot;Failed to Log In&quot;
End If
InternetCloseHandle (lLng_OpenHand)
Else
MsgBox &quot;Internet Channel Open Failed&quot;
End If

FTP_Get_Transfer = lBol_TranOK

End Function

'--------------------------------------------------------
Good Luck
------------
Select * from Users where Clue > 0
0 rows returned
 
Ignore the global declarations

Global gInt_Counter As Integer
Global gInt_TimeOut As Integer
Global mCol_Requests As New Collection
Global mCol_Responses As New Collection

Global gInt_LoopCount_Arr(999) As Integer

they have nothing to do with the FTP transfer.

Good Luck
------------
Select * from Users where Clue > 0
0 rows returned
 
There's an error if I start the app:
Compile error:

Constants, fixed-length strings, arrays, user-defined types and Declare statements not allowed as Public members of object modules
 
Either move this code to a module (.bas) or if you wish to keep this in the form, change the word &quot;Public&quot; to &quot;Private&quot; in the function declarations.
Good Luck
------------
Select * from Users where Clue > 0
0 rows returned
 
another error:
Compile error:

sub or function not defined



And it selects &quot;FtpGetFile&quot; on line 22
 
I'm sorry, I put the function declaration for the FtpPutFile instead of the FtpGetFile. The FtpGetFile declaration should read as follows:


Private Declare Function FtpGetFile Lib &quot;wininet.dll&quot; Alias &quot;FtpGetFileA&quot; (ByVal hConnect As Long, ByVal lpszRemoteFile As String, ByVal lpszNewFile As String, ByVal fFailIfExists As Long, ByVal dwFlagsAndAttributes As Long, ByVal dwFlags As Long, ByRef dwContext As Long) As Boolean
Good Luck
------------
Select * from Users where Clue > 0
0 rows returned
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top