iFTPFileSize Error 300: FileOpen failed when Firewall active?

Started by IJRobson, May 02, 2014, 07:50:17 AM

Previous topic - Next topic

IJRobson

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 Select
#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

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

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

SMF spam blocked by CleanTalk