vb登錄ftp
① vb中怎麼應用ftp
對於FTP,你可以使用Execute方法執臘擾行FTP命令SIZE獲得文件大小。然後在StateChanged事件中可以獲得返回的文件大小。
Private Sub Command1_Click()
Inet1.Execute "ftp://127.0.0.1", "SIZE 1.gif"
End Sub
Private 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 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
MsgBox strData
End Select
End Sub
對於HTTP下載,你判局睜可以用GetHeader(Content-length)來獲得文件大小。但不是所有HTTP下載時都能獲得文件長度,特別是通過代理伺服器下載文件時。如:
Private Sub Form_Load()
Inet1.Execute "http://askpro.yeah.net/"
End Sub
Private Sub Inet1_StateChanged(ByVal State As Integer)
If State = icResponseReceived Then
MsgBox "File size is " & Inet1.GetHeader("Content-Length")
End If
End Sub
② VB中怎麼寫,打開之後就進入一個FTP,自動輸入密碼。讀取到FTP上的文件
添加一個部件「Microsoft Internet Transfer Control」然後在窗體上添加一個此對象「Inet1」,設置屬性Protocol:2-icFTPRemoteHost:你的FTP伺服器IPUsername:你的用戶名Password:你的密碼 然後再用相關FTP命令讀取伺服器中的文件.
③ VB閾炬帴鍒癴tp錛屽苟浼犻佹枃浠訛紝鑷鍔ㄨ嗙洊鍘熸湁鏂囦歡
璇峰弬鑰,閲囩撼!璋㈣阿!
1,鍒╃敤Inet鎺т歡涓婁紶鏂囦歡
鏍煎紡: Inet1.Execute , "put 鏈鍦版枃浠 榪滅▼鏂囦歡"
鑼冧緥:
'鍒濆嬪寲Inet鎺т歡
Inet1.Protocol = icFTP
Inet1.url = "ftp://u0501901.k1.13939.org"
Inet1.RemotePort = 21
Inet1.UserName = "u0501901"
Inet1.Password = "750531179574"
label3.Caption = "姝e湪涓婁紶....."
'鍏堝叧闂褰撳墠鐨勬暟鎹搴撳瓨榪炴帴
cn.Close
Inet1.Execute , "put" & " " & App.Path & "\vbhelp.mdb" & " " & "/vbhelp/vbhelp.mdb"
Do While Inet1.StillExecuting
DoEvents
Loop
label3.Caption = "涓婁紶鎴愬姛"
'閲嶆柊榪炴帴鏁版嵁搴
dbconnect
2 ?鍒╃敤Inet鎺т歡涓嬭澆鏂囦歡
鏍煎紡錛 inet1.execute , "get 榪滅▼鏂囦歡 鏈鍦版枃浠"錛屾敞鎰忕┖鏍
'鍒濆嬪寲INET1鎺т歡
Inet1.Protocol = icFTP
Inet1.url = "ftp://u0501901.k1.13939.org"
Inet1.RemotePort = 21
Inet1.UserName = "u0501901"
Inet1.Password = "750531179574"
label3.Caption = "姝e湪涓嬭澆...."
'鏍煎紡錛 inet1.execute , "get 榪滅▼鏂囦歡 鏈鍦版枃浠"錛屾敞鎰忕┖鏍
Inet1.Cancel
Inet1.Execute , "GET /vbhelp/vbhelp.mdb c:\temp\vbhelp.mdb"
Do While Inet1.StillExecuting
DoEvents
Loop
label3.Caption = "涓嬭澆鎴愬姛"
3 ?鍒╃敤INET鎺т歡寤虹珛榪滅▼鐨勬枃浠跺す
Inet1.AccessType = icUseDefault
Inet1.RemotePort = 21
Inet1.Protocol = icFTP
Inet1.url = "u0711084.k1.13939.org"
Inet1.UserName = "u0711084"
Inet1.Password = "750531179574"
Inet1.Execute , "mkdir vbtest"
Do While Inet1.StillExecuting
DoEvents
Loop
Inet1.Execute , "close"
Inet1.Execute , "quit"
MsgBox "鎴愬姛寤虹珛鏂囦歡澶"
4 ?鍒╃敤INET鎺т歡鍒犻櫎榪滅▼鏂囦歡澶
鏂規硶璺熷緩絝嬫枃浠跺す涓鏍鳳紝鍒犻櫎鍛戒護涓簉mdir錛屼絾鍙鑳藉垹闄ょ┖鐩褰曪紝鍒犻櫎鏂囦歡鐢╠elete
④ VB鎵句竴孌礔TP浠g爜瀹炵幇
鐢╒B浠g爜瀹炵幇瀵笷TP鐨勪笂浼犲拰涓嬭澆.鍦ㄧ綉涓婃壘鍒頒簡涓鏂規硶.
榪欎釜鏂規硶鏄鐢↖NTERNET浼犺緭鎺т歡鏉ュ疄鐜扮殑.
娣誨姞浜咺NTERNET浼犺緭鎺т歡鍚嶸B浠g爜濡備笅"
'鍒濆嬪寲鎺т歡鐨勫睘鎬:
With Inet1
.URL = "ftp://192.168.0.50"
.UserName = "user"
.Password = "123"
.Protocol = icFTP
.RequestTimeout = 120
End With
,鍦‵TP鏍圭洰褰曚笅鍒涘緩鏂囦歡澶筧bc
Call Inet1.Execute(, "mkdir abc")
,鍦‵TP鏍圭洰褰曚笅杞123.txt鍒癉鐩
Call Inet1.Execute(, "get 123.txt d:\123.txt")
'鎶奷:\123.txt涓婁紶鍒癋TP鏍圭洰褰
Call Inet1.Execute(, "put d:\123.txt 123.txt")
'鎶奷:\123.txt涓婁紶鍒癋TP鏍圭洰褰
Call Inet1.Execute(, "send d:\123.bmp")