📄 ftp.frm
字号:
VERSION 5.00
Object = "{48E59290-9880-11CF-9754-00AA00C00908}#1.0#0"; "MSINET.OCX"
Begin VB.Form frmFTP
BorderStyle = 1 'Fixed Single
Caption = "Get a Text File via FTP"
ClientHeight = 2805
ClientLeft = 45
ClientTop = 330
ClientWidth = 4695
LinkTopic = "Form1"
MaxButton = 0 'False
MinButton = 0 'False
ScaleHeight = 2805
ScaleWidth = 4695
StartUpPosition = 3 'Windows Default
Begin VB.TextBox txtLog
Height = 735
Left = 120
MultiLine = -1 'True
ScrollBars = 2 'Vertical
TabIndex = 9
Top = 2040
Width = 4455
End
Begin InetCtlsObjects.Inet Inet1
Left = 3840
Top = 120
_ExtentX = 1005
_ExtentY = 1005
_Version = 393216
AccessType = 1
Protocol = 2
RemotePort = 21
URL = "ftp://"
End
Begin VB.CommandButton cmdGetFile
Caption = "Get the file"
Height = 375
Left = 120
TabIndex = 8
Top = 1560
Width = 4455
End
Begin VB.TextBox txtPassword
Height = 285
IMEMode = 3 'DISABLE
Left = 1440
PasswordChar = "*"
TabIndex = 7
Top = 1200
Width = 3135
End
Begin VB.TextBox txtUserName
Height = 285
Left = 1440
TabIndex = 5
Text = "anonymous"
Top = 840
Width = 3135
End
Begin VB.TextBox txtFile
Height = 285
Left = 1440
TabIndex = 3
Text = "disclaimer.txt"
Top = 480
Width = 3135
End
Begin VB.TextBox txtSite
Height = 285
Left = 1440
TabIndex = 2
Text = "ftp.microsoft.com"
Top = 120
Width = 3135
End
Begin VB.Label lblPassword
Alignment = 1 'Right Justify
Caption = "Password:"
Height = 285
Left = 120
TabIndex = 6
Top = 1200
Width = 1215
End
Begin VB.Label lblUserName
Alignment = 1 'Right Justify
Caption = "Username:"
Height = 285
Left = 120
TabIndex = 4
Top = 840
Width = 1215
End
Begin VB.Label lblFile
Alignment = 1 'Right Justify
Caption = "File to retrieve:"
Height = 285
Left = 120
TabIndex = 1
Top = 480
Width = 1215
End
Begin VB.Label lblSite
Alignment = 1 'Right Justify
Caption = "FTP site:"
Height = 285
Left = 360
TabIndex = 0
Top = 120
Width = 975
End
End
Attribute VB_Name = "frmFTP"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
' Fig. 19.7
' Downloading a text file via FTP
Option Explicit
Private Sub cmdGetFile_Click()
Dim command As String
Inet1.URL = txtSite.Text
Inet1.UserName = txtUserName.Text
Inet1.Password = txtPassword.Text
command = "get " & txtFile.Text & _
" C:\temp\" & txtFile.Text
txtLog.Text = _
txtLog.Text & "COMMAND: " & command & vbNewLine
Call Inet1.Execute(, command)
End Sub
Private Sub Inet1_StateChanged(ByVal State As Integer)
Select Case State
Case icResolvingHost
txtLog.Text = txtLog.Text & "Resolving host" & vbCrLf
Case icHostResolved
txtLog.Text = txtLog.Text & "Host resolved" & vbCrLf
Case icConnecting
txtLog.Text = _
txtLog.Text & "Connecting to host" & vbCrLf
Case icConnected
txtLog.Text = _
txtLog.Text & "Connected to host" & vbCrLf
Case icRequesting
txtLog.Text = txtLog.Text & "Sending request" & vbCrLf
Case icRequestSent
txtLog.Text = txtLog.Text & "Request sent" & vbCrLf
Case icReceivingResponse
txtLog.Text = _
txtLog.Text & "Receiving response" & vbCrLf
Case icResponseReceived
txtLog.Text = _
txtLog.Text & "Response received" & vbCrLf
Case icDisconnecting
txtLog.Text = _
txtLog.Text & "Disconnecting from host" & vbCrLf
Case icDisconnected
txtLog.Text = _
txtLog.Text & "Disconnected from host" & vbCrLf
Case icError
txtLog.Text = txtLog.Text & "Error occurred" & vbCrLf
Case icResponseCompleted
Dim data As Variant
txtLog.Text = txtLog.Text & _
"Repsonse completed. All data received." & vbCrLf
' write data to a file
Open txtFile.Text For Binary Access Write As #1
' get a chunk
' Not: can use icByteArray as the second argument
' to receive a binary file like an executable
data = Inet1.GetChunk(1024, icString)
Do While LenB(data) > 0
Put #1, , data
' get a chunk
data = Inet1.GetChunk(1024, icString)
Loop
Put #1, , data
Close #1
End Select
txtLog.SelStart = Len(txtLog.Text)
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -