Author Topic: iFTPFileSize Error 300: FileOpen failed when Firewall active?  (Read 21348 times)

IJRobson

  • Jr. Member
  • **
  • Posts: 94
Re: iFTPFileSize Error 300: FileOpen failed when Firewall active?
« Reply #35 on: May 23, 2014, 11:11:02 am »
Using the iFTPFileExist workaround the System is stable but regularly reports the FTP / Firewall issues.

So I thought I would try using the FTP LIST Command to get a full list of the Files in the Directory.  The added bonus of this command is on our FTP Server this also returns the File Sizes so I can use this information instead of iFTPFileSize per File.

I have created this UDF to get this List:
Code: Winbatch
#DefineFunction FtpListFileNames(ConHandle)
   size = 65536
   buf = BinaryAlloc( size )
   ;Get address of buffer
   bufaddr = IntControl ( 42, buf, 0, 0, 0 )
   BinaryEodSet( buf, size )

    ;PASV (recommended before calling LIST)
   datahandle = iFtpCmd( conhandle, "PASV", "", @ASCII )    
   If datahandle == 0      
                Return
   EndIf
   ;GET LIST
   datahandle = iFtpCmd( conhandle, "LIST", "", @ASCII )
   If datahandle == 0
                Return  
        EndIf
   count = iReadDataBuf( datahandle , bufaddr, size )
   ;Grab each file name

        Start = 0
   CRLF_Ptr = 0
   FileList = ""

   While CRLF_Ptr < count
      CRLF_Ptr = BinaryIndex( buf, Start, @CRLF, @FWDSCAN)

                If CRLF_Ptr == 0 then
                        Break
                Endif

                FileInfo = StrTrim(BinaryPeekStr( buf, Start, (CRLF_Ptr - Start)))

                parsedata(FileInfo)

                If Param3 <> "<DIR>" then
                        Size = Param3
                        Filename = ""

                        For A = 4 to Param0
                                Filename = StrCat(Filename, " ", Param%A%)
                        Next A

                        FileList = StrCat(FileList, @CRLF, Filename, @TAB, Size)
                Endif
                CRLF_Prt = CRLF_Ptr + 2
                Start = CRLF_Prt
   EndWhile
   ;Cleanup
   BinaryFree( buf )
        FileList = StrTrim(FileList)
   Return FileList
#EndFunction

This works fine but when I call it a second time (within the same FTP Connection) it returns a empty FileList.  I presume there must be an extra FTP Command I need to send before I can obtain the File List again?

Any ideas?

Thanks

Deana

  • Wilson WindowWare Tech Support
  • Pundit
  • *****
  • Posts: 1183
  • WinBatch® can do it.
    • WinBatch Tech Support Database
Re: iFTPFileSize Error 300: FileOpen failed when Firewall active?
« Reply #36 on: May 23, 2014, 11:31:23 am »
It appears the UDF you created was based off this code in the tech database: http://techsupt.winbatch.com/webcgi/webbatch.exe?techsupt/nftechsupt.web+WIL~Extenders/WinInet+FtpListFileNames~UDF.txt

You should probably be calling iClose on the handle returned from the iFtpCmd before returning from your UDF.
Deana F.
Technical Support
Wilson WindowWare Inc.

IJRobson

  • Jr. Member
  • **
  • Posts: 94
Re: iFTPFileSize Error 300: FileOpen failed when Firewall active?
« Reply #37 on: May 23, 2014, 11:50:45 am »
I based my code on the Example in the iFTPCmd Extender Help Page, which looks the same as the Tech Support UDF.

Anyway you were correct adding iClose fixed the Problem.

Thanks