WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

WinInet
plus

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

iFtpCmd Issues

 Keywords:  

Question:

I keep getting 'WIL Extender Error 318: iFtpDirGet Failed', if I call iFtpDirGet after calling iFtpCmd with the LIST command.

Answer:

iFtpCmd using the LIST verb, expects a response. Therefore you MUST call iReadData of iReadDatabuf before doing any other ftp operations!
AddExtender( "WWINT44I.DLL" )
tophandle = iBegin( 0, "", "" )
conhandle = iHostConnect( tophandle,"ftp.windowware.com", @FTPPASSIVE, "", "" )
If conhandle == 0
   Message( "ERROR" , "Unable to connect to host" )
   Exit
EndIf

newdir = iFtpDirChange( conhandle, "/wwwftp/wb01" )
If newdir == 0
      Message( "Change Dir", "NOT Successful" )
      iClose( conhandle )
      iClose( tophandle )
      Exit
EndIf

cmdhandle=iFtpCmd(conhandle,"PASV","",@ASCII)
If cmdhandle==0
   err=iGetResponse()
   Message("iFtpCmd Error",err)
   iClose(cmdhandle)
   iClose(conhandle)
   iClose(tophandle)
   Exit
EndIf

cmdhandle=iFtpCmd(conhandle,"LIST","",@ASCII) ;works
If cmdhandle==0
   err=iGetResponse()
   Message("iFtpCmd Error",err)
   iClose(cmdhandle)
   iClose(conhandle)
   iClose(tophandle)
   Exit
EndIf

;iReadDatabuf is used to read the pending data from the iFtpCmd LIST command
size = 65536
buf = BinaryAlloc( size )
bufaddr = IntControl ( 42, buf, 0, 0, 0 )  ;Get address of buffer
bytes = iReadDataBuf( cmdhandle, bufaddr, size )
BinaryEodSet( buf, size )
list = BinaryPeekStr(buf, 0, bytes)

;replace CRLF with TAB
list = StrReplace( list, @CRLF, @TAB )

AskItemlist('iFtpCmd - LIST', list, @TAB, @UNSORTED, @SINGLE )

;Clean up
iClose(cmdhandle)
iClose(conhandle)
iClose(tophandle)


Sample 2: Read the data in chunks ( used for very large amounts fo data )

AddExtender( "WWINT44I.DLL" )
tophandle = iBegin( 0, "", "" )
conhandle = iHostConnect( tophandle,"ftp.windowware.com", @FTPPASSIVE, "", "" )
If conhandle == 0
   Message( "ERROR" , "Unable to connect to host" )
   Exit
EndIf

newdir = iFtpDirChange( conhandle, "/wwwftp/wb01" )
If newdir == 0
      Message( "Change Dir", "NOT Successful" )
      iClose( conhandle )
      iClose( tophandle )
      Exit
EndIf

cmdhandle=iFtpCmd(conhandle,"PASV","",@ASCII)
If cmdhandle==0
   err=iGetResponse()
   Message("iFtpCmd Error",err)
   iClose(cmdhandle)
   iClose(conhandle)
   iClose(tophandle)
   Exit
EndIf

cmdhandle=iFtpCmd(conhandle,"LIST","",@ASCII) ;works
If cmdhandle==0
   err=iGetResponse()
   Message("iFtpCmd Error",err)
   iClose(cmdhandle)
   iClose(conhandle)
   iClose(tophandle)
   Exit
EndIf

;iReadDatabuf is used to read the pending data from the iFtpCmd LIST command
chunksize = 1024

bytes = 1
list = ""
While bytes!=0
  buf = BinaryAlloc( chunksize )
  bufaddr = IntControl ( 42, buf, 0, 0, 0 )  ;Get address of buffer
  bytes = iReadDataBuf( cmdhandle, bufaddr, chunksize )
  BinaryEodSet( buf, chunksize )
  chunk = BinaryPeekStr(buf, 0, bytes)
  ;Pause( 'Chunk', chunk )
  list = list:chunk
  BinaryFree( buf)
EndWhile

;replace CRLF with TAB
list = StrReplace( list, @CRLF, @TAB )

AskItemlist('iFtpCmd - LIST', list, @TAB, @UNSORTED, @SINGLE )

;Clean up
iClose(cmdhandle)
iClose(conhandle)
iClose(tophandle)

Article ID:   W16887
File Created: 2017:07:28:13:58:47
Last Updated: 2012:10:09:15:09:27