Code-Beispiel
FTP
Lizenz: | Erster Autor: | Letzte Bearbeitung: |
GPL | jakidomi | 06.12.2016 |
Hinweis: Den Inhalt der benötigten "explorer.bi" findet man hier: explorer.bi
#include once "explorer.bi"
#include once "file.bi"
declare function instrrev2(st as string,w as string)as integer
function instrrev2(st as string,w as string)as integer
dim as integer a,b
do
b=a
a=instr(b+1,st,w)
loop until a<b
return b
end function
dim shared as string ftpserveraddresse,ftpserverbenutzer,ftpserverpasswort,ftptypetempalt,ftptypetemp,ftp_app_adr
dim shared as integer ftpstarttime,ftpsendanz
ftpstarttime=timer
ftp_app_adr=environ("systemroot")+"\system32\ftp.exe"
ftpserveraddresse="Serveraddresse"
ftpserverbenutzer="Benutzer"
ftpserverpasswort="Passwort"
declare function ftpget (von as string,datei as string, nach as string) as string
declare function ftpsend (datei as string, nach as string) as integer
declare function ftp (comand() as string) as string
declare function ftpconnect () as integer
declare function ftpconnected() as integer
declare function ftpmsend (dateien() as string,von as string,nach as string) as integer
declare function ftpmget (dateien() as string,von as string,nach as string) as integer
declare function ftpdir (von as string,lines() as string) as integer
declare function ftpdircreate(ordner as string) as integer
declare function ftpdirdelete(ordner as string) as integer
declare function ftpkill (datei as string) as integer
declare function ftpdatalist (ordner as string,dateien() as string,dirs() as string)as integer
declare function ftpcd (cd as string) as integer
declare function ftpremotev as string
declare function ftptype (typ as integer) as integer
'declare function ftpdirexists (ordner as string) as integer
'declare function ftpfileexists (datei as string) as integer
function ftpget (von as string,datei as string, nach as string)as string
OPEN "FTP.temp" FOR OUTPUT AS #1
PRINT #1, "open "+ftpserveraddresse
PRINT #1, ftpserverbenutzer
PRINT #1, ftpserverpasswort
if not von="" then PRINT #1, "cd "+von
PRINT #1, "get "+datei+" "+nach
PRINT #1, "quit"
CLOSE #1
SHELL ftp_app_adr+" -v -i -s:FTP.temp > log.txt"
KILL "FTP.tmp"
open "log.txt" for input as #1
dim as string text,text2
do
line input #1,text
text2+=text+chr(13,10)
loop until eof(1)
close #1
kill "log.txt"
return text2
end function
function ftpsend (datei as string,nach as string)as integer
dim as integer i
OPEN "FTP.temp" FOR OUTPUT AS #1
PRINT #1, "open "+ftpserveraddresse
PRINT #1, ftpserverbenutzer
PRINT #1, ftpserverpasswort
PRINT #1, "cd "+nach
PRINT #1, "send "+datei
PRINT #1, "quit"
CLOSE #1
SHELL ftp_app_adr+" -v -i -s:FTP.temp > log.txt"
open "log.txt" for input as #1
dim as string text,text2
do
i+=1
line input #1,text
text2+=text+chr(13,10)
loop until eof(1)
close #1
KILL "FTP.tmp"
kill "log.txt"
return i
end function
function ftp (comand () as string) as string
OPEN "FTP.temp" FOR OUTPUT AS #1
PRINT #1, "open "+ftpserveraddresse
PRINT #1, ftpserverbenutzer
PRINT #1, ftpserverpasswort
dim as integer i
dim as string a
for i=1 to ubound(comand)
if not comand(i)="" then PRINT #1, comand(i)
next
PRINT #1, "quit"
CLOSE #1
a=ScHELL (ftp_app_adr+" -v -i -s:FTP.temp")
KILL "FTP.tmp"
return a
end function
function ftpconnect () as integer
OPEN "FTP.temp" FOR OUTPUT AS #1
PRINT #1, "open "+ftpserveraddresse
PRINT #1, ftpserverbenutzer
PRINT #1, ftpserverpasswort
CLOSE #1
SHELL ftp_app_adr+" -v -i -s:FTP.temp "
KILL "FTP.tmp"
return 0
end function
function ftpconnected () as integer
OPEN "FTP.temp" FOR OUTPUT AS #1
PRINT #1, "open "+ftpserveraddresse
PRINT #1, ftpserverbenutzer
PRINT #1, ftpserverpasswort
PRINT #1, "quit"
CLOSE #1
SHELL ftp_app_adr+" -v -i -s:FTP.temp "
KILL "FTP.tmp"
return 0
end function
function ftpmsend (dateien() as string,von as string,nach as string) as integer
dim as string temp
dim as integer i,f=freefile,tim
OPEN exepath+"\data\server\FTPmsend.temp" FOR OUTPUT AS #f
PRINT #f, "open "+ftpserveraddresse
PRINT #f, ftpserverbenutzer
PRINT #f, ftpserverpasswort
if not nach="" then PRINT #f, "cd "+nach
for i=1 to ubound(dateien)
if not von="" and not dateien(i)="" then PRINT #f,"send "+von+"\"+dateien(i)
next
PRINT #f, "quit"
CLOSE #f
SHELL ftp_app_adr+" -i -s:"+exepath+"\data\server\FTPmsend.temp"
KILL exepath+"\data\server\FTPmsend.tmp"
f=freefile
open exepath+"\data\server\logsend.txt" for append as #f
ftpsendanz+=i-1:tim=timer
if not i-1=0 and tim=ftpstarttime+60 then ftpstarttime=timer:?#f,ftpsendanz;" dateien gesendet um "+time+" am "+date
'?#f,ftpsendtime,tim,ftpsendanz
close #f
return 0
end function
function ftpmget (dateien() as string,von as string, nach as string) as integer
dim as string a
dim as integer i,f=freefile,f2
kill exepath+"\data\server\FTPmget.temp"
OPEN exepath+"\data\server\FTPmget.temp" FOR OUTPUT AS #f
PRINT #f, "open "+ftpserveraddresse
PRINT #f, ftpserverbenutzer
PRINT #f, ftpserverpasswort
if not von="" then PRINT #f, "cd "+von
if not nach="" then PRINT #1, "lcd "+nach
for i=1 to ubound(dateien)
PRINT #f,"get "+dateien(i)+" "+nach+"\"+dateien(i)
next
PRINT #f, "quit"
CLOSE #f
SHELL (ftp_app_adr+" -v -i -s:"+exepath+"\data\server\FTPmget.temp")
f=freefile
return 1
end function
function ftpdir(von as string,lines() as string) as integer
dim as string a
dim as integer b,c,d,e
OPEN exepath+"\data\server\FTPdir.temp" FOR OUTPUT AS #1
PRINT #1, "open "+ftpserveraddresse
PRINT #1, ftpserverbenutzer
PRINT #1, ftpserverpasswort
if not von="" then PRINT #1, "cd "+von
PRINT #1,"dir"
PRINT #1, "quit"
CLOSE #1
a=SCHELL (ftp_app_adr+" -v -i -s:"+exepath+"\data\server\FTPdir.temp")
?A
KILL exepath+"\data\server\FTPdir.tmp"
redim lines(0)
c=instrrev(a,chr(13,10))
b=instr(a,chr(13,10))
d=1
redim preserve lines(d)
lines(d)=mid(a,1,b)
do:d+=1
e=b+1
b=instr(e,a,chr(13,10))
redim preserve lines(d)
lines(d)=mid(a,e+1,(b-e))
loop until b=c
c=d
for d=d to ubound(lines)
lines(d)=""
redim lines(d)
next
if a="" then return 0 else return c
end function
function ftpdircreate(ordner as string) as integer
dim as integer a,f=freefile
dim as string z,ci,r
a=instrrev(ordner,"/")-1
if not a=0 and not a=-1 then
ci=left(ordner,a)
r=right(ordner,(len(ordner)-a)-1)
else
ci=""
r=ordner
end if
if r="" then return 0:exit function
OPEN exepath+"\data\server\FTPdircreate.temp" FOR OUTPUT AS #f
PRINT #f, "open "+ftpserveraddresse
PRINT #f, ftpserverbenutzer
PRINT #f, ftpserverpasswort
if not ci="" then ?#f,"cd "+ci
if not r="" then ?#f,"mkdir "+r
PRINT #f, "quit"
CLOSE #f
z=SCHELL (ftp_app_adr+" -v -s:"+exepath+"\data\server\FTPdircreate.temp")
dim as string lines()
dim as integer b,c,d,e
for d=0 to ubound(lines)
lines(d)=""
redim lines(d)
next
c=instrrev(z,chr(13,10))
b=instr(z,chr(13,10))
d=1
redim preserve lines(d)
lines(d)=mid(z,1,b)
do:d+=1
e=b+1
b=instr(e,z,chr(13,10))
redim preserve lines(d)
lines(d)=mid(z,e+1,(b-e))
loop until b=c
redim preserve lines(d+1)
lines(d+1)=right(z,b-1)
KILL exepath+"\data\server\FTPdircreate.tmp"
if ubound(lines)<5 then ?ubound(lines):return -5:exit function
select case left(lines(5),len(lines(5))-1)
case "","quit","ftp> quit","ftp> mkdir "+r
d=0
case r+": File exists"
d=-1
case else
d=-2
end select
if len(left(lines(5),len(lines(5))-1))>40 then d=1
select case left(lines(4),len(lines(4))-1)
case ci+": No such file or directory"
d=-3
end select
return d
end function
function ftpdirdelete(ordner as string) as integer
dim as integer a,f=freefile
dim as string z,ci,r
a=instrrev(ordner,"/")-1
if not a=0 and not a=-1 then
ci=left(ordner,a)
r=right(ordner,(len(ordner)-a)-1)
else
ci=""
r=ordner
end if
if r="" then return 0:exit function
OPEN exepath+"\data\server\FTPdirdelete.temp" FOR OUTPUT AS #f
PRINT #f, "open "+ftpserveraddresse
PRINT #f, ftpserverbenutzer
PRINT #f, ftpserverpasswort
if not ci="" then ?#f,"cd "+ci
if not r="" then ?#f,"rmdir "+r
PRINT #f, "quit"
CLOSE #f
z=SCHELL (ftp_app_adr+" -v -i -s:"+exepath+"\data\server\FTPdirdelete.temp")
KILL exepath+"\data\server\FTPdirdelete.tmp"
dim as string lines()
dim as integer b,c,d,e
for d=0 to ubound(lines)
lines(d)=""
redim lines(d)
next
c=instrrev(z,chr(13,10))
b=instr(z,chr(13,10))
d=1
redim preserve lines(d)
lines(d)=mid(z,1,b)
do:d+=1
e=b+1
b=instr(e,z,chr(13,10))
redim preserve lines(d)
lines(d)=mid(z,e+1,(b-e))
loop until b=c
redim preserve lines(d+1)
lines(d+1)=right(z,b-1)
KILL exepath+"\data\server\FTPdircreate.tmp"
if ubound(lines)<5 then return -5:exit function
select case left(lines(5),len(lines(5))-1)
case "","quit","ftp> quit","ftp> rmdir "+r
d=0
case r+": Directory not empty"
d=-1
case r+": No such file or directory"
d=-2
case else
d=-3:?z
end select
if len(left(lines(5),len(lines(5))-1))>40 then d=1
return d
end function
function ftpkill(datei as string) as integer
dim as integer a=instrrev(datei,"/")-1,f=freefile
dim as string ordner,file,z
if not a=0 and not a=-1 then
ordner=left(datei,a)
file=right(datei,(len(datei)-a)-1)
else
ordner=""
file=datei
end if
OPEN exepath+"\data\server\FTPdelete.temp" FOR OUTPUT AS #f
PRINT #f, "open "+ftpserveraddresse
PRINT #f, ftpserverbenutzer
PRINT #f, ftpserverpasswort
if not ordner="" then ?#f,"cd "+ordner
PRINT #f, "delete "+file
PRINT #f, "quit"
CLOSE #f
z=SCHELL (ftp_app_adr+" -v -i -s:"+exepath+"\data\server\FTPdelete.temp")
dim as string lines()
dim as integer b,c,d,e
for d=0 to ubound(lines)
lines(d)=""
redim lines(d)
next
c=instrrev(z,chr(13,10))
b=instr(z,chr(13,10))
d=1
redim preserve lines(d)
lines(d)=mid(z,1,b)
do:d+=1
e=b+1
b=instr(e,z,chr(13,10))
redim preserve lines(d)
lines(d)=mid(z,e+1,(b-e))
loop until b=c
redim preserve lines(d+1)
lines(d+1)=right(z,b-1)
KILL exepath+"\data\server\FTPdelete.tmp"
if ubound(lines)<5 then return 1:exit function
select case left(lines(5),len(lines(5))-1)
case "","quit","ftp> quit","ftp> delete "+file
d=1
case file+": No such file or directory"
d=-1
case else
d=-2
end select
if len(left(lines(5),len(lines(5))-1))>40 then d=0
return d
end function
function ftpdatalist(ordner as string,dateien() as string,dirs() as string)as integer
dim as integer f=freefile,a,b,c,d,o
dim as string z,temp()
OPEN exepath+"\data\server\FTPdatalist.temp" FOR OUTPUT AS #f
PRINT #f, "open "+ftpserveraddresse
PRINT #f, ftpserverbenutzer
PRINT #f, ftpserverpasswort
if not ordner="" then ?#f,"cd "+ordner
PRINT #f, "ls"
PRINT #f, "quit"
CLOSE #f
z=SCHELL (ftp_app_adr+" -v -i -s:"+exepath+"\data\server\FTPdatalist.temp"):?z:getkey
kill exepath+"\data\server\FTPdatalist.temp"
if instrrev(z,chr(13,10))<=3 then return 0:exit function
a=0
for b=1 to 4
a=instr(a+1,z,chr(13,10))
next
b=instrrev(z,chr(13,10))
c=0
redim temp(c)
do:c+=1
redim preserve temp(c)
o=d
d=a+1
a=instr(d,z,chr(13,10))
temp(c)=mid(z,d+1,(a-d)-1)
loop until a=b
redim preserve temp(c-1)
if instr(z,": No such file or directory") then return 0:exit function
a=0:b=0:o=c
redim dateien(0)
redim dirs(0)
for c=1 to ubound(temp)-1
if instrrev(temp(c),".")=0 then
if not temp(c)=".." and not temp(c)=". ." then
if not instrrev(temp(c), any ".")=0 or not instr(temp(c), any ".")=0 then goto gg
b+=1
redim preserve dirs(b)
dirs(b)=temp(c)
endif
else
gg:
if not temp(c)=".." and not temp(c)=". ." then
a+=1
redim preserve dateien(a)
dateien(a)=temp(c)
endif
endif
next
return o
end function
function ftpcd (cd as string) as integer
dim as string a,b,c=chr(34)
dim as integer p1,p2,p3,f=freefile
OPEN exepath+"\data\server\FTPrmv.temp" FOR OUTPUT AS #f
PRINT #f, "open "+ftpserveraddresse
PRINT #f, ftpserverbenutzer
PRINT #f, ftpserverpasswort
PRINT #f, "cd "+cd
PRINT #f, "quit"
close #f
a=SCHELL (ftp_app_adr+" -v -i -n -s:"+exepath+"\data\server\FTPrmv.temp"):sleep 300,1
kill exepath+"\data\server\FTPrmv.temp"
if instr(a,"No such file or directory")=0 then return 1 else return 0
end function
function ftpremotev as string
dim as string a,b,c=chr(34)
dim as integer p1,p2,p3,f=freefile
OPEN exepath+"\data\server\FTPrmv.temp" FOR OUTPUT AS #f
PRINT #f, "open "+ftpserveraddresse
PRINT #f, ftpserverbenutzer
PRINT #f, ftpserverpasswort
PRINT #f, "pwd"
PRINT #f, "quit"
CLOSE #f
a=ScHELL (ftp_app_adr+" -v -i -s:"+exepath+"\data\server\FTPrmv.temp"):sleep 300,1
if a="" then return "error 1":exit function
KILL exepath+"\data\server\FTPrmv.temp"
p1=instr(a,c)
p2=instr(p1+1,a,c)
p3=instr(a,"257 "+c+"/")
b=mid(a,p1+1,(p2-p1)-1)
if p3=0 then return "error 2":exit function
if b="" then return "error 3"::exit function else return b
end function
function ftptype (typ as integer) as integer
dim as string a,b
dim as integer f=freefile
if ftptypetempalt="" then ftptypetempalt="binary"
if ftptypetemp="" then ftptypetemp="binary"
select case typ
case 1
b="ascii"
case 2
b="binary"
case 3
b="append"
case 4
if not ftptypetemp=ftptypetempalt then b=ftptypetemp
case else
return 0:exit function
end select
if b="" or ftptypetempalt=b then return 0:exit function
if not ftptypetemp="" then ftptypetempalt=ftptypetemp
ftptypetemp=b
OPEN exepath+"\data\server\FTPtype.temp" FOR OUTPUT AS #f
PRINT #f, "open "+ftpserveraddresse
PRINT #f, ftpserverbenutzer
PRINT #f, ftpserverpasswort
PRINT #f, "type "+b
PRINT #f, "quit"
CLOSE #f
a=ScHELL (ftp_app_adr+" -v -i -s:"+exepath+"\data\server\FTPtype.temp"):sleep 300,1
KILL exepath+"\data\server\FTPtype.temp"
if a="" then return 0:exit function
?b
return 1
end function
Zusätzliche Informationen und Funktionen | |||||||
---|---|---|---|---|---|---|---|
|