Click here to Skip to main content
15,885,939 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Alright, the issue is the FtpFindFirstFile command. My goal is to get a directory listing of the current directory on the mainframe server.
The command runs fine, but returns nothing. The connection is made fine, and I can use FtpGetFile to download a file. It abends when it gets to the setting of the variable "sFileName" because of the cFileName of pData being Nothing. The commented out Left command above it is the example I went off of to get it to work in VB.NET.

The real question here is why PDATA is not being populated with anything.

sFilter comes in with "*"
connect comes in with my connection number

I'm lost at this point.

VB
Private Structure WIN32_FIND_DATA
       Public dwFileAttributes As Integer
       Public ftCreationTime As Long
       Public ftLastAccessTime As Long
       Public ftLastWriteTime As Long
       Public nFileSizeHigh As UInteger
       Public nFileSizeLow As UInteger
       Public dwReserved0 As Integer
       Public dwReserved1 As Integer
       Public cFileName As String
       Public cAlternate As String
   End Structure

Public Function GetDirectoryListing(ByVal sFilter As String, ByVal connect As Integer) As IList
        Dim hFind As Long
        Dim nLastError As Integer
        Dim dError As Integer
        Dim pData As WIN32_FIND_DATA
        Dim sFilename As String
        Dim mDirCol As IList = Nothing
        hFind = FtpFindFirstFile(connect, sFilter, pData, INTERNET_FLAG_RELOAD Or INTERNET_FLAG_NO_CACHE_WRITE, 0&)
        nLastError = Err.LastDllError
        If hFind = 0 Then
            If (nLastError <> ERROR_NO_MORE_FILES) Then
                MsgBox("oh snap")
                Me.Close()
            End If
            Return Nothing
            Exit Function
        End If
        dError = NO_ERROR
        Dim bRet As Boolean
        'sFilename = Left(pData.cFileName, InStr(1, pData.cFileName, "(1, 0)", vbBinaryCompare) - 1)
        sFilename = Mid(pData.cFileName, 1, InStr(1, pData.cFileName, "(1, 0)", vbBinaryCompare) - 1)
Posted

You have this question indexed as VB.Net; is there any reason why you are using the API rather than the .Net Framework? The object to look for is FtpWebRequest in the System.Net namespace. It might be easier to find documentation for those methods.
 
Share this answer
 
I suspect your problem lies in your declaration of the WIN32_FIND_DATA structure. Including string fields in an Windows API data structure usualy requires something more complex than a simple Public strField As String declaration.

I find the P/Invoke website[^] a useful resource in such circumstances. You should investigate their definition of the WIN32_FIND_DATA[^] data structure. I'd also recommend checking the declaration of the FtpFindFirstFile[^] and compare it with your declaration.

Let me add that I also agree with Gregory Gadow's post. If you are using VB.NET, it is generally better to use the appropriate Framework classes.
 
Share this answer
 
(I couldn't comment on either of yours for some reason)

XML
The problem I ran into with the FtpWebRequest in the .NET framework seemed to require me to connect using a FTP type connection that our mainframe server would return a 501 error (Not Implemented or Not Supported) when trying to connect.  Currently I'm connecting using the InternetConnect.
I'm pretty new to VB, and this is my first real use of a lot of it. I'm usually stuck doing JCL/COBOL/Assembler work.  Nothing fun.
I used the declaration of the FtpFindFirstFile from P/Invoke and it returned something.
<pre>"潖畬敭唠楮⁴†删晥牥敲⁤硅⁴獕摥删捥浦䰠敲汣䈠歬穓䐠潳杲䐠湳浡e⪤福䵰ν䵰ν훜福⪴福䞤禈䚨禈䛌禈㉜禺㉜禺䎤禷ذ禺窈禹㉜禺㉜禺䎤禷ذ禺窈禹㉜禺ذ禺窈禹䎤禷"

Not quite sure what. Still reading into the use of these commands. Thanks for getting me past that though!
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900