Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ftp.Dir with subfolders
#1
How can I find or enumerate files in Ftp server include subfolders like in GetFilesInFolder?
#2
It would be slow. For example, when testing with http://ftp.quickmacros.com, getting file list takes 700-800 ms for each folder. Is it OK?
If it is your site, maybe you can do it for example in php. Then should be fast.
#3
In this case, it doesn't matter if it is slow.
#4
Member function Ftp.DirAll
Code:
Copy      Help
;/
function $pattern ARRAY(STRINT)&a [flags] ;;flags: 0 files, 1 folders, 2 both, 4 include subfolders

;Gets names of files in an ftp folder and optionally in subfolders.

;pattern - filename with wildcard characters. Cannot contain spaces.
;;;Examples: "*" (all in current ftp directory), "" (the same), "*.htm", "abc/*" (relative to current ftp directory), "/abc/*" (full path).
;a - receives filenames and paths (relative or full, depending on pattern) in a[?].s. For folders, a[?].i will be 1, for files - 0.

;EXAMPLE
;out
;Ftp f.Connect("ftp.xxx.com" "********" "********")
;f.DirSet("public_html")
;ARRAY(STRINT) a
;f.DirAll("*" a 2)
;int i
;for i 0 a.len
,;out "%s%s" a[i].s iif(a[i].i " (folder)" "")


a=0
int f=flags&3
if(f=3) end ES_BADARG
if(flags&4 and f=0) f=2
if(empty(pattern)) pattern="*"
str sp.getpath(pattern)

lpstr s=Dir(pattern f)
rep
,if(!s) break
,sel(s) case [".",".."] goto g1
,int isf=m_fd.fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY!=0
,
,if((isf and f) or (!isf and f!=1))
,,STRINT& r=a[]
,,r.s.from(sp s)
,,r.i=isf
,;g1
,s=Dir

if(flags&4=0) ret

int i j
for i 0 a.len
,&r=a[i]
,if(!r.i) continue
,str sp2.from(r.s "/" pattern+sp.len+(sp.len!0))
,ARRAY(STRINT) a2
,DirAll(sp2 a2 flags)
,for(j 0 a2.len)
,,&r=a2[j]
,,if((r.i and flags&3) or (!r.i and flags&3!=1)) a[]=r

if(flags&3=0) for(i a.len-1 -1 -1) if(a[i].i) a.remove(i)
#5
It's perfect.

Thank you.
#6
How can I use INTERNET_FLAG_NO_CACHE_WRITE and INTERNET_FLAG_RELOAD in FTP?
#7
I created:

Member function Ftp.Dir2
Code:
Copy      Help
function$ [$_file] [flags] [WIN32_FIND_DATA&info] ;;flags: 0 file, 1 folder, 2 both, 3 previous. ;;usa flaps INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_RELOAD

;Finds or enumerates files in FTP server.
;Returns found filename.
;This function is similar to <help "::/Functions/IDP_DIR.html">dir</help>.
;_file can contain wildcard characters. Cannot contain spaces.
;If _file not used or is "", finds next matching file.
;Member variable m_fd.fd contains more information about file. If info is not 0, copies m_fd.fd to info.

;Note: This function does not support Unicode.


if(!m_fd) m_fd._new
if(getopt(nargs)=0 or flags&3=3) flags=m_fd.flags; else m_fd.flags=flags

if(!empty(_file)) ;;find first file
,if(m_fd.hfind) InternetCloseHandle(m_fd.hfind)
,m_fd.hfind=FtpFindFirstFile(m_hi _file &m_fd.fd INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_RELOAD 0)
,if(!m_fd.hfind) ret
,;filter
,int isdir=m_fd.fd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY
,sel(flags)
,,case 0: if(isdir) goto next ;;must be file
,,case 1: if(!isdir) goto next ;;must be folder
,if(&info) info=m_fd.fd
,ret &m_fd.fd.cFileName ;;and leave open handle for enumeration
else ;;find next file
,if(!m_fd.hfind) ret
,;next
,if(InternetFindNextFile(m_fd.hfind &m_fd.fd)) goto filter
,;nomore
,InternetCloseHandle(m_fd.hfind); m_fd.hfind=0

and works.


Forum Jump:


Users browsing this thread: 1 Guest(s)