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.

FtpListFileNames UDF

 Keywords: iFtpCmd FTP LIST FTPLIST 

#DefineFunction FtpListFileNames(host,ftppath,userid,pswd) 
	size=65536
	buf=BinaryAlloc(size)
	;Get address of buffer
	bufaddr=IntControl (42, buf, 0, 0, 0)
	BinaryEodSet(buf, size)
	
	AddExtender("WWINT44i.DLL")
	tophandle=iBegin(0,"","")
	conhandle=iHostConnect(tophandle,host,@FTPPASSIVE, userid, pswd)
	if conhandle==0
	  message("ERROR","Unable to connect to host")
	  exit
	endif
	
	Newdir=iFtpDirChange(conhandle,ftppath)
	if newdir==0
		message("Change Dir","NOT Successful")
		iClose(conhandle)
	   iClose(tophandle)
		exit
	endif

	;PASV (Recommended before calling LIST)
	cmdhandle=iFtpCmd(conhandle,"PASV","",@ASCII) ;works
	if cmdhandle==0
	   err=iGetResponse()
	   Message("Error",err)
		iClose(conhandle)
	   iClose(tophandle)
	   exit
	endif

	;GET LIST
	cmdhandle=iFtpCmd(conhandle,"LIST","",@ASCII) ;works
	if cmdhandle==0
	   err=iGetResponse()
	   Message("Error",err)
		iClose(conhandle)
	   iClose(tophandle)
	   exit
	endif
	
	count=iReadDataBuf(cmdhandle,bufaddr,size)
	;Grab each file name
	crlf_ptr = 0
	filelist = ""
	x = 1
	While crlf_ptr < count
	   crlf_ptr = BinaryIndex(buf,crlf_ptr,@CRLF,@FWDSCAN)
		space_ptr = BinaryIndex(buf,crlf_ptr," ",@BACKSCAN)
		file = BinaryPeekStr(buf, space_ptr+1, crlf_ptr-space_ptr-1)
		if x !=1 ;skip line with file size total
		  filelist = StrCat(filelist,@Tab,file)
		endif
		crlf_ptr = crlf_ptr+2
		x = x + 1
	Endwhile
	filelist = StrTrim(filelist)
		
	;Cleanup
	BinaryFree(buf)
	iClose(cmdhandle)
	iClose(conhandle)
	iClose(tophandle)

	
	return filelist
#EndFunction


host="ftp.windowware.com"
ftppath = "/wwwftp/wb01"
userid="anonymous"
pswd="me@mydomain.com"
list  = FtpListFileNames(host,ftppath,userid,pswd) 
AskItemList(StrCat("FTP LIST - ",host,ftppath),list,@tab,@sorted,@single)
exit

Article ID:   W15434
File Created: 2014:05:23:11:32:10
Last Updated: 2014:05:23:11:32:10