关于wininet,ftp编程中一个问题。。(50分)

  • 主题发起人 主题发起人 ccniao
  • 开始时间 开始时间
C

ccniao

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure connectFtpSite(ftpSite:string;user:string;pass:string);<br>var<br>hFind:Pointer;<br>wfd:TWin32FindData;<br>hInternet,hConnect:Pointer;<br>begin<br>hInternet:=InternetOpen(pchar('Application'),0,nil,nil,0);<br>if hInternet=nil &nbsp;then begin<br>showmessage('InternetOpen error!');<br>exit;<br>end;<br>if (user='') and (pass='') then<br>&nbsp; &nbsp; hConnect:=InternetConnect(hInternet,pchar(ftpSite),INTERNET_DEFAULT_FTP_PORT,nil,nil,INTERNET_SERVICE_FTP,INTERNET_FLAG_EXISTING_CONNECT OR INTERNET_FLAG_PASSIVE,$0)<br>&nbsp; &nbsp; else<br>&nbsp; &nbsp; hConnect:=InternetConnect(hInternet,pchar(ftpSite),INTERNET_DEFAULT_FTP_PORT,pchar(user),pchar(pass),INTERNET_SERVICE_FTP,0,$0);<br><br>if hConnect=nil then begin<br>showmessage('InternetConnect error!');<br>exit;<br>end;<br><br>showmessage('connect ok!');<br><br>if FtpSetCurrentDirectory(hConnect,pchar('/a/'))=false then &nbsp; begin<br>&nbsp; showmessage('error!');<br>&nbsp;exit;<br>&nbsp;end;<br>hFind:=FtpFindFirstFile(hConnect,pchar('*.*'),wfd,0,$0);<br>if hFind=nil then<br>&nbsp; showmessage('error');<br><br><br>if FtpSetCurrentDirectory(hConnect,pchar('/b/'))=false then &nbsp; begin<br>&nbsp; &nbsp;showmessage('error!');<br>&nbsp; &nbsp;exit;<br>&nbsp; &nbsp;end;<br><br>&nbsp;hFind:=FtpFindFirstFile(hConnect,pchar('*.*'),wfd1,0,$0);<br>if hFind=nil then &nbsp; &nbsp;//这里出现error<br>&nbsp; showmessage('error');<br><br>InternetCloseHandle(hConnect);<br>InternetCloseHandle(hInternet);<br>end;<br><br>ftp服务器上根目录下有a,b两个目录,并且都有文件在里面<br>现在在标记的地方出现了 error,可见跳转目录后在用ftpFindFirstFile就不行了。<br>到底是为什么啊?这个样子的话还怎么实现遍历服务器上的文件呢?<br>
 
很简单:FTP每次的操作都会使用ConnectHandle失效(只能用一次),所以要再次连接。<br>就OK了。<br><br>记得加分哦! ^_*
 

Similar threads

I
回复
0
查看
731
import
I
I
回复
0
查看
838
import
I
I
回复
0
查看
380
import
I
I
回复
0
查看
558
import
I
后退
顶部