Module : directory
<module title="Directory listing routines">
<include file="dirent"/>
<include file="sys/stat"/>
<table name="dir">
<fields name="key" type="string" use="User defined key to this data"
name="file" type="string" use="Filename"
name="type" type="[File Directory Hidden]"
name="size" type="number"
name="user_id"
name="user_rights" type="[Normal Execute Readonly None]"
name="group_id"
name="group_rights" type="[Normal Execute Readonly None]"
name="public_rights" type="[Normal Execute Readonly None]"
name="last_use" type="time"
name="last_change" type="time">
<index fields="key file">
</table>
<routine name="addentry"
parameter="key" type="constr"
parameter="file" type="constr"
parameter="type" type="number"
parameter="size" type="number"
parameter="last_use" type="time"
parameter="last_change" type="time" local>
add dir as d
d.key=key
d.file=file
d.type=type
d.last_use=last_use
d.last_change=last_change
d.size=size
update
</routine>
<routine name="directory"
parameter="dir" type="constr" use="Directory name to read"
parameter="key" type="constr" default="none" use="Key to administrate this directory"
system>
DIR *d=opendir(v_dir);
struct dirent *e;
struct stat b;
char *f;
e=readdir(d);
while(e!=0)
{ f=scon(scon(scpy(v_dir), "/"), e->d_name);
stat(f, &b);
rtn_addentry(v_key, e->d_name, (S_ISDIR(b.st_mode))?1:0,
b.st_size, b.st_atime, b.st_mtime);
e=readdir(d);
free(f);
}
closedir(d);
</routine>
<routine name="getftp"
parameter="path" type="string"
parameter="export" type="string" local>
directory(path, export)
search dir where dir.key=export and dir.type="Directory" and
dir.file<>"." and dir.file<>".."
dir=tbl_search_dir(export, null) loop
if dir=null or (dir.key > export) then break endif
if tbl_get_dir_key(dir) = export and tbl_get_dir_type(dir) = 1 and tbl_get_dir_file(dir) <> "." and tbl_get_dir_file(dir) <> ".." then
getftppath+"/"+dir.file, export+"/"+dir.file)
dir.recnr+=1
endif
if dir=null then
dir=getpointer(0, 0, 1)
else
dir=ptrplus1(dir, 1)
endif
do
dir.recnr-=1
next</routine>
<routine name="ftp"
parameter="path" type="string" use="Full path to directory to export"
parameter="export" type="string" use="Full path in remote sytem"
parameter="types" type="string" use="File types to export divided by |"
parameter="site" type="string" use="Site name for export"
parameter="user" type="string" use="User name to log on with"
parameter="last" type="time" use="Previous export time">
var ftpf as stream
var ldir as string
ftpf=create("ftp.txt")
output "open "+site to ftpf
output "user "+user to ftpf
getftp(path, "/")
separate types as tps by "|"
search dir where dir.type="File" and
right(dir.file, length(tps)+1)="."+tps
dir=tbl_search_dir(null, null) loop
if dir=null then break endif
if tbl_get_dir_type(dir) = 0 and right(tbl_get_dir_file(dir), length(tps) + 1) = "." + tps then
ifldir<>dir.key then
ldir=dir.key
output "lcd "+path+ldir to ftpf
output "cd ~/"+export+ldir to ftpf
endif
output "put "+dir.file to ftpf
dir.recnr+=1
endif
if dir=null then
dir=getpointer(0, 0, 1)
else
dir=ptrplus1(dir, 1)
endif
do
dir.recnr-=1
next next
output "quit" to ftpf
close(ftpf)
</routine>
Copyright (C) 2001 Jurjen J. Stellingwerff