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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

wininet calls problem

Status
Not open for further replies.

Vika

Programmer
Jul 31, 2000
29
0
0
US
I am using wininet functions to do FTP calls.

The connection is working just fine, but when I am trying to use FTPGetCurrentDirectory Function to get Directory Name, the function returns False. Now that I got error, I am trying to figure out what error I got by using GetLastError() Function, but the function returnes 0, which means that "Operation Completed successfully".

Does anybody knows what I am doing wrong?

Here is my code.
Code:
Public Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Public Const INTERNET_OPEN_TYPE_DIRECT = 1
Public Const INTERNET_DEFAULT_FTP_PORT = 21
Public Const INTERNET_SERVICE_FTP = 1
Public Const GENERIC_READ = &H80000000
Public Const GENERIC_WRITE = &H40000000
Public Const FTP_TRANSFER_TYPE_ASCII = &H1

Public sFileName As String
Public sServerName As String
Public sPassword As String
Public SUserName As String

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 FtpGetCurrentDirectory Lib "wininet.dll" _
    Alias "FtpGetCurrentDirectoryA" _
    (ByVal hFile As Long, ByVal sBuffer As String, _
    ByRef lBufferLength As Long) As Boolean
    
Public Declare Function GetLastError Lib "kernel32" () As Long

Public Function ConnectFTPHost()
Dim iDirectory As Boolean
Dim lDirLen As Long
Dim sBuffer As String
Dim lErrNo As Long
'sFileName = ""
sServerName = FTP_Host
sPassword = FTP_Password
SUserName = FTP_User
Screen.MousePointer = vbHourglass

'get a connection

hInternetSession = InternetOpen("SSTrans", INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
hFtpSession = InternetConnect(hInternetSession, sServerName, INTERNET_DEFAULT_FTP_PORT, SUserName, _
sPassword, INTERNET_SERVICE_FTP, iflags, icontext)

 If hInternetSession <> 0 Then
  Connected = -1
  MsgBox &quot;You are connected now!&quot;
 End If
 
 lDirLen = MAX_PATH
 
 iDirectory = FtpGetCurrentDirectory(hFtpSession, sBuffer, lDirLen)
 
 If iDirectory = False Then
  lErrNo = GetLastError()
  DoEvents
 End If
 DoEvents
End Function

 
There was no error the Api call &quot;Public Declare Function ftpGetCurrentDirectory Lib &quot;wininet.dll&quot; _
Alias &quot;ftpGetCurrentDirectoryA&quot; _
(ByVal hFile As Long, ByVal sBuffer As String, _
ByRef lBufferLength As Long) As Boolean&quot;

returns a True or False value. That is what Boolean means.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top