这是MSDN的帮助,看看吧:Execute 方法示例 该示例列举了一系列使用 Execute 方法的 FTP 操作。该示例假定窗体中有三个 TextBox 控件。第一个控件 txtURL 包含 FTP 服务器的 URL。第二个控件 txtRemotePath 包含特殊命令所需的附加信息。第三个控件 txtResponse 包含服务器的响应。Private Sub cmdChangeDirectory_Click() '将目录改变到 txtRemotePath。 Inet1.Execute txtURL.Text, "CD " & _ txtRemotePath.Text End SubPrivate Sub cmdDELETE_Click() '删除 txtRemotePath 中的目录。 Inet1.Execute txtURL.Text, "DELETE " & _ txtRemotePath.Text End SubPrivate Sub cmdDIR_Click() Inet1.Execute txtURL.Text, "DIR FindThis.txt" End SubPrivate Sub cmdGET_Click() Inet1.Execute txtURL.Text, _ "GET GetThis.txt C:\MyDocuments\GotThis.txt" End SubPrivate Sub cmdSEND_Click() Inet1.Execute txtURL.Text, _ "SEND C:\MyDocuments\Send.txt SentDocs\Sent.txt" End SubPrivate Sub Inet1_StateChanged(ByVal State As Integer) 'State = 12 时,用 GetChunk 方法检索服务器的响应。 Dim vtData As Variant ' Data variable. Select Case State '...没有列举其它情况。 Case icError '11 '出现错误时,返回 ResponseCode 和 ResponseInfo。 vtData = Inet1.ResponseCode & ":" & _ Inet1.ResponseInfo Case icResponseCompleted ' 12
Dim vtData As Variant Dim strData As String Dim bDone As Boolean: bDone = False '取得第一个块。 vtData = Inet1.GetChunk(1024, icString) DoEvents Do While Not bDone strData = strData & vtData '取得下一个块。 vtData = Inet1.GetChunk(1024, icString) DoEvents If Len(vtData) = 0 Then bDone = True End If Loop txtData.Text = strData End Select End Sub
Private Sub Command1_Click() Inet1.Execute "ftp://upload:[email protected]", "put c:\odbcconf.log odbcconf.log" End SubPrivate Sub Inet1_StateChanged(ByVal State As Integer) Dim MsgStr As String Select Case State Case icNone MsgStr = "无状态可报告。" Case icHostResolvingHost MsgStr = "正在查询所指定的主机的 IP 地址。" Case icHostResolved MsgStr = "已成功地找到所指定的主机的 IP 地址。" Case icConnecting MsgStr = "正在与主机连接。" Case icConnected MsgStr = "已与主机连接成功。" Case icRequesting MsgStr = "正在向主机发送请求。" Case icRequestSent MsgStr = "发送请求已成功。" Case icReceivingResponse MsgStr = "正在接收主机的响应。" Case icResponseReceived MsgStr = "已成功地接收到主机的响应。" Case icDisconnecting MsgStr = "正在解除与主机的连接。" Case icDisconnected MsgStr = "已成功地与主机解除了连接。" Case icError MsgStr = "与主机通讯时出现了错误。" Case icResponseCompleted MsgStr = "该请求已经完成,并且所有数据均已接收到。" End Select Debug.Print MsgStr End Sub
补充: Case icError MsgStr = "与主机通讯时出现了错误。" If Inet1.ResponseCode = 12003 Then MsgStr = MsgStr & vbCrLf & "用户名或密码错误!"
msdn上有介绍的
Inet1.Execute "ftp://User:[email protected]/", "put c:\net.log net.log"
该示例列举了一系列使用 Execute 方法的 FTP 操作。该示例假定窗体中有三个 TextBox 控件。第一个控件 txtURL 包含 FTP 服务器的 URL。第二个控件 txtRemotePath 包含特殊命令所需的附加信息。第三个控件 txtResponse 包含服务器的响应。Private Sub cmdChangeDirectory_Click()
'将目录改变到 txtRemotePath。
Inet1.Execute txtURL.Text, "CD " & _
txtRemotePath.Text
End SubPrivate Sub cmdDELETE_Click()
'删除 txtRemotePath 中的目录。
Inet1.Execute txtURL.Text, "DELETE " & _
txtRemotePath.Text
End SubPrivate Sub cmdDIR_Click()
Inet1.Execute txtURL.Text, "DIR FindThis.txt"
End SubPrivate Sub cmdGET_Click()
Inet1.Execute txtURL.Text, _
"GET GetThis.txt C:\MyDocuments\GotThis.txt"
End SubPrivate Sub cmdSEND_Click()
Inet1.Execute txtURL.Text, _
"SEND C:\MyDocuments\Send.txt SentDocs\Sent.txt"
End SubPrivate Sub Inet1_StateChanged(ByVal State As Integer)
'State = 12 时,用 GetChunk 方法检索服务器的响应。 Dim vtData As Variant ' Data variable.
Select Case State
'...没有列举其它情况。
Case icError '11
'出现错误时,返回 ResponseCode 和 ResponseInfo。
vtData = Inet1.ResponseCode & ":" & _
Inet1.ResponseInfo
Case icResponseCompleted ' 12
Dim vtData As Variant
Dim strData As String
Dim bDone As Boolean: bDone = False '取得第一个块。
vtData = Inet1.GetChunk(1024, icString)
DoEvents Do While Not bDone
strData = strData & vtData
'取得下一个块。
vtData = Inet1.GetChunk(1024, icString)
DoEvents If Len(vtData) = 0 Then
bDone = True
End If
Loop
txtData.Text = strData
End Select
End Sub
Inet1.Execute "ftp://upload:[email protected]", "put c:\odbcconf.log odbcconf.log"
End SubPrivate Sub Inet1_StateChanged(ByVal State As Integer)
Dim MsgStr As String
Select Case State
Case icNone
MsgStr = "无状态可报告。"
Case icHostResolvingHost
MsgStr = "正在查询所指定的主机的 IP 地址。"
Case icHostResolved
MsgStr = "已成功地找到所指定的主机的 IP 地址。"
Case icConnecting
MsgStr = "正在与主机连接。"
Case icConnected
MsgStr = "已与主机连接成功。"
Case icRequesting
MsgStr = "正在向主机发送请求。"
Case icRequestSent
MsgStr = "发送请求已成功。"
Case icReceivingResponse
MsgStr = "正在接收主机的响应。"
Case icResponseReceived
MsgStr = "已成功地接收到主机的响应。"
Case icDisconnecting
MsgStr = "正在解除与主机的连接。"
Case icDisconnected
MsgStr = "已成功地与主机解除了连接。"
Case icError
MsgStr = "与主机通讯时出现了错误。"
Case icResponseCompleted
MsgStr = "该请求已经完成,并且所有数据均已接收到。"
End Select
Debug.Print MsgStr
End Sub
Case icError
MsgStr = "与主机通讯时出现了错误。"
If Inet1.ResponseCode = 12003 Then MsgStr = MsgStr & vbCrLf & "用户名或密码错误!"