㈠ VB中如何讀取ftp伺服器上面的text文本文件
使用Inet控制項進行FTP操作
Inet1.Protocol = icFTP
Inet1.RemoteHost = p_ServerName ' 伺服器IP或者域名
Inet1.RemotePort = CInt(p_ServerPort) 'FTP埠
Inet1.UserName = uName 'FTP帳號
Inet1.Password = uPWS 'FTP密碼
Inet1.Execute "", "ls"
ri = Inet1.StillExecuting
Do While ri
ri = Inet1.StillExecuting
DoEvents
Loop
vd = Inet1.GetChunk(1024, icString)
判斷服務的FTP是否連接成功
下面下載伺服器上的text數據,假設文件名為1.txt
p_pathDir 為當前軟體運行目錄,後面一個字元自帶 \,如e:\1111\
tepFile 臨時文件
工作方式是先下載這個文件下為,然後判斷本地是否存在,如果存在,則打開文件讀取內容,如果不存在,則說明伺服器上不存在這個文件,但要注意,如果文件過大的話,可能需要等待的時候比較長。
tepFile = p_pathDir & "1.txt_"
'Inet1.Execute hDir, "get 1.txt " & tepFile
Inet1.Execute "", "GET 1.txt " & tepFile
ri = Inet1.StillExecuting
Do While ri
ri = Inet1.StillExecuting
DoEvents
Loop
If Dir(tepFile) = "" Then
Inet1.Cancel
MsgBox "文件不存在" & InetState, vbOKOnly + vbExclamation, "系統提示"
Else
Inet1.Cancel
'這里已經存在,與本地操作文件一樣,請打開獲取內容,不再詳細寫出
'
End If
㈡ VBA如何訪問ftp路徑的文件
需要先判斷該文件是否存在。
VBA是到一個ftp伺服器上打開指定的文件,但是需要先判斷該文件是否存在,在那個cFTP的類中找到一段代碼。
㈢ vb6.0用inet空間獲取ftp文件列表的問題
從上面代碼看, OperationStyle變數沒有定義,所以出現上述問題。
其他代碼不變,只對下面代碼進行修改即可:
Case 12 『不要8
Select Case OperationStyle
Case 2
Text1.Text = Text1.Text & vbCrLf & "成功改變目錄"
listserver
Case Else
Text1.Text = Text1.Text & vbCrLf & "成功列出目錄"
ListView1.ListItems.Clear
inetdata = Inet1.GetChunk(1024, 0)
If Trim(inetdata) <> 0 Then
temparray = Split(inetdata, vbCrLf, , vbTextCompare)
i = 0
Do While i < UBound(temparray)
If temparray(i) <> "" Then
deallist (temparray(i))
End If
i = i + 1
Loop
End If
End Select
End Select
Text1.SelLength = Len(Text1.Text)
End Sub