思路:

網(wǎng)站建設(shè)哪家好,找創(chuàng)新互聯(lián)公司!專注于網(wǎng)頁設(shè)計(jì)、網(wǎng)站建設(shè)、微信開發(fā)、微信小程序定制開發(fā)、集團(tuán)企業(yè)網(wǎng)站建設(shè)等服務(wù)項(xiàng)目。為回饋新老客戶創(chuàng)新互聯(lián)還提供了新市免費(fèi)建站歡迎大家使用!
1,使用ListBox1控件來存放搜索到的文件名,然后ListBox1.SelectedItem就可以返回選中項(xiàng)的文本;
2,利用獲得的選中項(xiàng)文本(即文件與路徑),使用打開文本文件的方法,讀取內(nèi)容顯示在文本框里。
public strData as string
'這段可以返回服務(wù)器中的第一級目錄名,保存在strData中, 如有多個(gè)文件夾名每個(gè)文件夾名會(huì)以空格分開。讀取時(shí)判段一下。
Inet1.Execute Inet1.URL, "dir """ dirName """"
Do
DoEvents
Loop While Inet1.StillExecuting = True
msgbox strData
'這段是進(jìn)入目錄中,要想獲得服務(wù)器中所有的文件夾名,就可以用遞規(guī)的辦法來獲得。
Inet1.Execute Inet1.URL, "cd """ dirName """"
Do
DoEvents
Loop While Inet1.StillExecuting = True
Private Sub Inet1_StateChanged(ByVal State As Integer)
Select Case State
Case 1
StatusBar1.Panels.Item(1).Text = "該控件正在查詢所指定的主機(jī)的 IP 地址"
Case 2
StatusBar1.Panels.Item(1).Text = "該控件已成功地找到所指定的主機(jī)的 IP 地址"
Case 3
StatusBar1.Panels.Item(1).Text = "該控件正在與主機(jī)連接"
Case 4
StatusBar1.Panels.Item(1).Text = "該控件已與主機(jī)連接成功"
Case 5
StatusBar1.Panels.Item(1).Text = "該控件正在向主機(jī)發(fā)送請求"
Case 6
StatusBar1.Panels.Item(1).Text = "該控件發(fā)送請求已成功"
Case 7
StatusBar1.Panels.Item(1).Text = "該控件正在接收主機(jī)的響應(yīng)"
Case 8
StatusBar1.Panels.Item(1).Text = "該控件已成功地接收到主機(jī)的響應(yīng)"
Case 9
StatusBar1.Panels.Item(1).Text = "該控件正在解除與主機(jī)的連接"
Case 10
StatusBar1.Panels.Item(1).Text = "該控件已成功地與主機(jī)解除了連接"
Case 11
MsgBox "與主機(jī)通訊時(shí)出現(xiàn)了錯(cuò)誤", vbInformation, "個(gè)人資料"
Case 12
Dim vtData As Variant
Dim bDone As Boolean
bDone = False
'取得第一個(gè)塊。
vtData = Inet1.GetChunk(1024, icString)
DoEvents
Do While Not bDone
strData = strData vtData
'取得下一個(gè)塊。
vtData = Inet1.GetChunk(1024, icString)
DoEvents
If Len(vtData) = 0 Then
bDone = True
End If
Loop
StatusBar1.Panels.Item(1).Text = "該請求已經(jīng)完成,并且所有數(shù)據(jù)均已接收到"
Case Else
StatusBar1.Panels.Item(1).Text = Inet1.ResponseCode ": " Inet1.ResponseInfo
End Select
End Sub
If My.Computer.Network.IsAvailable Then
'如果可用
Else
'不可用
End If
Public Sub DownloadFile ( _
address As Uri, _
destinationFileName As String, _
userName As String, _
password As String, _
showUI As Boolean, _
connectionTimeout As Integer, _
overwrite As Boolean, _
onUserCancel As UICancelOption _
)
參數(shù)
address
String 或 Uri。要下載的文件的路徑,包括文件名和主機(jī)地址。必選。
destinationFileName
String。下載文件的文件名和路徑。必選。
userName
String。要進(jìn)行身份驗(yàn)證的用戶名。默認(rèn)值為空字符串 ""。
password
String。要進(jìn)行身份驗(yàn)證的密碼。默認(rèn)值為空字符串 ""。
showUI
Boolean。指定是否顯示操作進(jìn)度。默認(rèn)為 False。
connectionTimeout
Int32。以毫秒為單位的超時(shí)間隔。默認(rèn)值為 100 秒。
overwrite
Boolean。指定是否改寫現(xiàn)有文件。默認(rèn)為 False。
onUserCancel
UICancelOption。指定當(dāng)用戶在對話框(此對話框在 ShowUI 設(shè)置為 True 時(shí)顯示)上單擊“取消”或“否”時(shí)的行為。默認(rèn)為 ThrowException。
步驟如下:
窗體上添加2個(gè)列表框,一個(gè)按鈕:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim MyDir As String = "C:\123"
'搜索并顯示子文件夾
ListBox1.Items.Clear()
For Each MySubDir As String In System.IO.Directory.GetDirectories(MyDir)
ListBox1.Items.Add(MySubDir)
Next
'搜索并顯示文件
ListBox2.Items.Clear()
For Each MyFile As String In System.IO.Directory.GetFiles(MyDir)
ListBox2.Items.Add(MyFile)
Next
End Sub
End Class
具體方法如下:”、打開Serv-U的配置管理界面puzb在“全局用戶”或者“域用戶”中選擇“創(chuàng)建cgko修改和刪除用戶帳戶”; 2、在“創(chuàng)建,修改和刪除用戶帳戶”的界面,選擇“添加”。;3、在“用戶屬性“對話框,“用戶信息”下的用戶名為:Anonymous,密碼為空,為其指定FTP的根目錄。 4、然后在“目錄訪問“選項(xiàng),點(diǎn)擊“添加”,為其指定訪問權(quán)限和目錄。 5、最后點(diǎn)擊“保存”6這樣我們就成功添加了匿名用戶。
MSDN上的,看看對你有沒有幫助。GOOD LUCK!
Imports System.Net
Imports System.IO
Module FtpSample
Sub Main(ByVal args() As String)
If args.Length = 0 OrElse args(0).Equals("/?") Then
DisplayUsage()
ElseIf args.Length = 1 Then
Download(args(0))
ElseIf args.Length = 2 Then
If args(0).Equals("/list") Then
List(args(1))
Else
Upload(args(0), args(1))
End If
Else
Console.WriteLine("Unrecognized argument.")
End If
End Sub
Private Sub DisplayUsage()
Console.WriteLine("USAGE:")
Console.WriteLine(" FtpSample [/? | FTP download URL | local file")
Console.WriteLine(" FTP upload URL | /list FTP list URL]")
Console.WriteLine()
Console.WriteLine("where")
Console.WriteLine(" FTP download URL URL of a file to download from an FTP server.")
Console.WriteLine(" FTP upload URL Location on a FTP server to upload a file to.")
Console.WriteLine(" FTP list URL Location on a FTP server to list the contents of.")
Console.WriteLine(" local file A local file to upload to an FTP server.")
Console.WriteLine()
Console.WriteLine(" Options:")
Console.WriteLine(" /? Display this help message.")
Console.WriteLine(" /list Specifies the list command.")
Console.WriteLine()
Console.WriteLine("EXAMPLES:")
Console.WriteLine(" Download a file FtpSample ")
Console.WriteLine(" Upload a file FtpSample upload.txt ")
End Sub
Private Sub Download(ByVal downloadUrl As String)
Dim responseStream As Stream = Nothing
Dim fileStream As FileStream = Nothing
Dim reader As StreamReader = Nothing
Try
Dim downloadRequest As FtpWebRequest = _
WebRequest.Create(downloadUrl)
Dim downloadResponse As FtpWebResponse = _
downloadRequest.GetResponse()
responseStream = downloadResponse.GetResponseStream()
Dim fileName As String = _
Path.GetFileName(downloadRequest.RequestUri.AbsolutePath)
If fileName.Length = 0 Then
reader = New StreamReader(responseStream)
Console.WriteLine(reader.ReadToEnd())
Else
fileStream = File.Create(fileName)
Dim buffer(1024) As Byte
Dim bytesRead As Integer
While True
bytesRead = responseStream.Read(buffer, 0, buffer.Length)
If bytesRead = 0 Then
Exit While
End If
fileStream.Write(buffer, 0, bytesRead)
End While
End If
Console.WriteLine("Download complete.")
Catch ex As UriFormatException
Console.WriteLine(ex.Message)
Catch ex As WebException
Console.WriteLine(ex.Message)
Catch ex As IOException
Console.WriteLine(ex.Message)
Finally
If reader IsNot Nothing Then
reader.Close()
ElseIf responseStream IsNot Nothing Then
responseStream.Close()
End If
If fileStream IsNot Nothing Then
fileStream.Close()
End If
End Try
End Sub
Private Sub Upload(ByVal fileName As String, ByVal uploadUrl As String)
Dim requestStream As Stream = Nothing
Dim fileStream As FileStream = Nothing
Dim uploadResponse As FtpWebResponse = Nothing
Try
Dim uploadRequest As FtpWebRequest = WebRequest.Create(uploadUrl)
uploadRequest.Method = WebRequestMethods.
' UploadFile is not supported through an Http proxy
' so we disable the proxy for this request.
uploadRequest.Proxy = Nothing
requestStream = uploadRequest.GetRequestStream()
fileStream = File.Open(fileName, FileMode.Open)
Dim buffer(1024) As Byte
Dim bytesRead As Integer
While True
bytesRead = fileStream.Read(buffer, 0, buffer.Length)
If bytesRead = 0 Then
Exit While
End If
requestStream.Write(buffer, 0, bytesRead)
End While
' The request stream must be closed before getting the response.
requestStream.Close()
uploadResponse = uploadRequest.GetResponse()
Console.WriteLine("Upload complete.")
Catch ex As UriFormatException
Console.WriteLine(ex.Message)
Catch ex As IOException
Console.WriteLine(ex.Message)
Catch ex As WebException
Console.WriteLine(ex.Message)
Finally
If uploadResponse IsNot Nothing Then
uploadResponse.Close()
End If
If fileStream IsNot Nothing Then
fileStream.Close()
End If
If requestStream IsNot Nothing Then
requestStream.Close()
End If
End Try
End Sub
Private Sub List(ByVal listUrl As String)
Dim reader As StreamReader = Nothing
Try
Dim listRequest As FtpWebRequest = WebRequest.Create(listUrl)
listRequest.Method = WebRequestMethods.
Dim listResponse As FtpWebResponse = listRequest.GetResponse()
reader = New StreamReader(listResponse.GetResponseStream())
Console.WriteLine(reader.ReadToEnd())
Console.WriteLine("List complete.")
Catch ex As UriFormatException
Console.WriteLine(ex.Message)
Catch ex As WebException
Console.WriteLine(ex.Message)
Finally
If reader IsNot Nothing Then
reader.Close()
End If
End Try
End Sub
End Module
可以通過設(shè)置 Credentials 屬性來指定用于連接服務(wù)器的憑據(jù),也可以將它們包含在傳遞給 Create 方法的 URI 的 UserInfo 部分中。
從 FTP 服務(wù)器下載文件時(shí),如果命令成功,所請求的文件的內(nèi)容即在響應(yīng)對象的流中。通過調(diào)用 GetResponseStream 方法,可以訪問此流。
如果使用 FtpWebRequest 對象向服務(wù)器上載文件,則必須將文件內(nèi)容寫入請求流,請求流是通過調(diào)用 GetRequestStream 方法或其異步對應(yīng)方法(BeginGetRequestStream 和 EndGetRequestStream 方法)獲取的。必須寫入流并在發(fā)送請求之前關(guān)閉該流。
請求是通過調(diào)用 GetResponse 方法或其異步對應(yīng)方法(BeginGetResponse 和 EndGetResponse 方法)發(fā)送到服務(wù)器的。請求的操作完成時(shí),會(huì)返回一個(gè) FtpWebResponse 對象。FtpWebResponse 對象提供操作的狀態(tài)以及從服務(wù)器下載的所有數(shù)據(jù)。
文章標(biāo)題:關(guān)于vb.netFTP查找的信息
URL地址:http://chinadenli.net/article1/dsgdgid.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)、網(wǎng)站收錄、關(guān)鍵詞優(yōu)化、App設(shè)計(jì)、用戶體驗(yàn)、企業(yè)網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)