⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 98.txt

📁 VB文章集(含API、窗口、数据库、多媒体、系统、文件、等等)
💻 TXT
📖 第 1 页 / 共 2 页
字号:
  lpvFindData 是同样的用户定义类型,用在FtpFindFirstFile 调用中存储文件信息。 

  下面是在路径中得到下一个文件的调用: 

blnRC = InternetFindNextFile(lngHINet, pData) 

  如果调用成功,blnRC 返回 True,否则 blnRC 为False。Err对象的LastDllError返回18表明再没有文件存在了。 

  现在再回来看看基本的四步:第1步和第2步(设置环境和连接服务器)应该已经完成。以下列出的第三步。最后一步,第四步,就清除环境和连接句柄,跟前面一样: 

Dim pData As WIN32_FIND_DATA 

Dim lngHINet As Long 

Dim intError As Integer 

Dim strTemp As String 

Dim blnRC As Boolean 



'init the filename buffer 

pData.cFileName = String(260, 0) 



'get the first file in the directory... 

lngHINet = FtpFindFirstFile(mlngINetConn, "*.*", pData, 0, 0) 



'how'd we do? 

If lngHINet = 0 Then 

  'get the error from the findfirst call 

  intError = Err.LastDllError 

   

  'is the directory empty? 

  If intError < > ERROR_NO_MORE_FILES Then 

    'whoa...a real error 

    卐rror handler? 

  End If 

   

Else 

   

  'we got some dir info... 

  'get the name 

  strTemp = Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1) 



  卻tore the file info someplace? 

       

  'now loop through the rest of the files... 

  Do 

    'init the filename buffer 

    pData.cFileName = String(260, 0) 

     

    'get the next item 

    blnRC = InternetFindNextFile(lngHINet, pData) 

     

    'how'd we do? 

    If Not blnRC Then 

     

      'get the error from the findnext call 

      intError = Err.LastDllError 

       

      'no more items 

      If intError < > 18 Then 

        'whoa...a real error 

        卐rror handler? 

         

        Exit Do 

       

      Else 

         

        'no more items... 

        Exit Do 

         

      End If 

       

    Else 

       

      'get the last item returned 

      strTemp = Left(pData.cFileName, InStr(1, pData.cFileName, String(1, 0), vbBinaryCompare) - 1) 

       

      卻tore the file info someplace? 



    End If 

     

  Loop 

   

  'close the handle for the dir listing 

  InternetCloseHandle lngHINet 

   

End If 



  现在可以看到,即使是有一些复杂的任务,例如列举路径,都可以简单地纳入这简单的四步过程:设置环境,连接主机,执行FTP任务,关闭环境和连接句柄。 

你自己的FTP ActiveX 服务器组件 

  要使这篇文章完整,本文包括一个FTP ActiveX 服务器组件的VB源代码。代码中包含3个类模块:clsITEM.CLS 、colITEM.CLS和 FTP.CLS。clsITEM.CLS 包含的类定义以clsITEM作为类名,在列举一个路径时包含着单独的文件信息。colITEM.CLS 包含的类定义以colItem作为类名,用于使用clsITEM 类的文件集合。最后FTP.CLS 包含的类定义以ASPFTP 作为类名,用于所有的FTP函数。我还要包含一个工程文件TP_CLASSES.VBP)。 

  除了源代码,还包含了每个函数的样本ASP文件,一个包含文件(ASPFTP2.INC) ,你可以将它包含在每个ASP文件中使一些函数的调用更简单。例如,这里是使用FTP Get 函数的ASP代码。服务器,电子邮件用户名,口令,远程和本地文件名,使用的传输类型(ASCII 或 Binary),当本地文件存在时是否覆盖,这些都被输入一个表单中(未显示)并用ASP Request 对象引用: 

< %@ LANGUAGE=VBScript % > 

< !--#Include File="aspftp2.inc"-- > 

< % 

'check to see if user submitted form 

If Request.Form("GetIt") < > "" Then 

Dim objFTP 

Dim strMsg 



'create reference to object 

Set objFTP = Server.CreateObject("NIBLACK.ASPFTP") 



'set the properties for the connection 

objFTP.sServerName = Request.Form("Server") 

objFTP.sUserID = Request.Form("User_ID") 

objFTP.sPassword = Request.Form("Password") 



'connect to the host 

If objFTP.bConnect Then 

'set the properties for the get function 

objFTP.bOverWrite = Request.Form("OverWrite") 

objFTP.lTransferType = Request.Form("Transfer_Type") 



'now get the file 

If objFTP.bGetFile(Request.Form("Remote_File"), Request.Form("Local_File")) Then 

  'get was successful 

  strMsg = "Get Successful!" 

Else 

  'get failed...let user know 

  strMsg = "Get Failed: " & objFTP.sError 

End If 

Else 

'connection failed...let user know 

strMsg = "Connection Failed: " & objFTP.sError 

End If 

   

'clean up... 

Set objFTP = Nothing 



Else 

'default return msg 

strMsg = "" 

End If 

% > 



  我还为许多许多FTP函数创建了uick?方法。基本上,你调用一种uick?方法,用来完成任务的所有参数都包含在方法调用中,而不用在ASP代码中设置每一个属性。举例说,这里的ASP代码使用FTP Get 函数。服务器,电子邮件用户名,口令,远程和本地文件名,使用的传输类型(ASCII 或 Binary),当本地文件存在时是否覆盖,这些都被输入一个表单中(未显示)并用ASP Request 对象引用。 



< %@ LANGUAGE=VBScript % > 

< !--#Include File="aspftp2.inc"-- > 

< % 

'check to see if user submitted form 

If Request.Form("GetIt") < > "" Then 

Dim objFTP 

Dim strMsg 



'create reference to object 

Set objFTP = Server.CreateObject("NIBLACK.ASPFTP") 



'now get the file 

If objFTP.bQGetFile(Request.Form("Server"), Request.Form("User_ID"), _ 

  Request.Form("Password"), Request.Form("Remote_File"), Request.Form("Local_File"), _ 

  Request.Form("Transfer_Type"), Request.Form("OverWrite")) Then 

  'get was successful 

  strMsg = "Get Successful!" 

Else 

  'get failed...let user know 

  strMsg = "Get Failed: " & objFTP.sError 

End If 

   

'clean up... 

Set objFTP = Nothing 



Else 

'default return msg 

strMsg = "" 

End If 

% > 

下面如何? 

  有了提供的源代码,你就已经有了一个FTP函数的ActiveX服务器组件。现在我们可以跟随同样的基本步骤,创建一个客户机侧的OCX ,你可以将其包含在你的HTML页中以允许用户从他们的PC进行FTP。还可以看看WinINet API提供的一些其它函数。例如你可以使用HTTP函数创建一个机器人,将Web 站点的内容拉回来,对所有的页进行索引。或者创建一个探测器,在一个预定的基础上, 

用HTTP函数检测Web 站点或Web 页的状态。用WinINet API所提供的功能,这些和更多的想法都可以相当简单地来探索。 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -