包含vb點(diǎn)虐 ftp類(lèi)的詞條

ftp上傳文件用vb點(diǎn)虐 怎么實(shí)現(xiàn)

My.Computer.Network.UploadFile(本地文件路徑,?ftp服務(wù)器路徑包括文件名,用戶(hù)名,密碼)

從策劃到設(shè)計(jì)制作,每一步都追求做到細(xì)膩,制作可持續(xù)發(fā)展的企業(yè)網(wǎng)站。為客戶(hù)提供做網(wǎng)站、成都網(wǎng)站制作、網(wǎng)站策劃、網(wǎng)頁(yè)設(shè)計(jì)、國(guó)際域名空間、雅安服務(wù)器托管、網(wǎng)絡(luò)營(yíng)銷(xiāo)、VI設(shè)計(jì)、 網(wǎng)站改版、漏洞修補(bǔ)等服務(wù)。為客戶(hù)提供更好的一站式互聯(lián)網(wǎng)解決方案,以客戶(hù)的口碑塑造優(yōu)易品牌,攜手廣大客戶(hù),共同發(fā)展進(jìn)步。

VB點(diǎn)虐 連接FTP操作

MSDN上的,看看對(duì)你有沒(méi)有幫助。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

可以通過(guò)設(shè)置 Credentials 屬性來(lái)指定用于連接服務(wù)器的憑據(jù),也可以將它們包含在傳遞給 Create 方法的 URI 的 UserInfo 部分中。

從 FTP 服務(wù)器下載文件時(shí),如果命令成功,所請(qǐng)求的文件的內(nèi)容即在響應(yīng)對(duì)象的流中。通過(guò)調(diào)用 GetResponseStream 方法,可以訪問(wèn)此流。

如果使用 FtpWebRequest 對(duì)象向服務(wù)器上載文件,則必須將文件內(nèi)容寫(xiě)入請(qǐng)求流,請(qǐng)求流是通過(guò)調(diào)用 GetRequestStream 方法或其異步對(duì)應(yīng)方法(BeginGetRequestStream 和 EndGetRequestStream 方法)獲取的。必須寫(xiě)入流并在發(fā)送請(qǐng)求之前關(guān)閉該流。

請(qǐng)求是通過(guò)調(diào)用 GetResponse 方法或其異步對(duì)應(yīng)方法(BeginGetResponse 和 EndGetResponse 方法)發(fā)送到服務(wù)器的。請(qǐng)求的操作完成時(shí),會(huì)返回一個(gè) FtpWebResponse 對(duì)象。FtpWebResponse 對(duì)象提供操作的狀態(tài)以及從服務(wù)器下載的所有數(shù)據(jù)。

vb點(diǎn)虐 2008如何操作FTP服務(wù)器?比如登錄并保持登錄狀態(tài),然后遍歷根目錄及指定的目錄,以獲

具體方法如下:”、打開(kāi)Serv-U的配置管理界面puzb在“全局用戶(hù)”或者“域用戶(hù)”中選擇“創(chuàng)建cgko修改和刪除用戶(hù)帳戶(hù)”; 2、在“創(chuàng)建,修改和刪除用戶(hù)帳戶(hù)”的界面,選擇“添加”。;3、在“用戶(hù)屬性“對(duì)話框,“用戶(hù)信息”下的用戶(hù)名為:Anonymous,密碼為空,為其指定FTP的根目錄?!?、然后在“目錄訪問(wèn)“選項(xiàng),點(diǎn)擊“添加”,為其指定訪問(wèn)權(quán)限和目錄?!?、最后點(diǎn)擊“保存”6這樣我們就成功添加了匿名用戶(hù)。

vb點(diǎn)虐 ftp上傳文件

Dim OpenFileDialog As New OpenFileDialog

OpenFileDialog.InitialDirectory = My.Computer.FileSystem.SpecialDirectories.MyDocuments

OpenFileDialog.Filter = "文本文件(*.jpg)|*.jpg|所有文件(*.*)|*.*"

If (OpenFileDialog.ShowDialog(Me) = System.Windows.Forms.DialogResult.OK) Then

Dim FileName As String = OpenFileDialog.FileName

' TODO: 在此處添加打開(kāi)文件的代碼。

textbox1.Text = FileName

End If

第一個(gè)按鈕 上傳

Dim filelast As String = fileaddbefore.Text.Substring(fileaddbefore.Text.LastIndexOf("."), fileaddbefore.Text.Length - fileaddbefore.Text.LastIndexOf("."))

MessageBox.Show(filelast)

My.Computer.Network.UploadFile(textbox1.Text, "" 文件名.Text filelast, "登錄名1", "登錄密碼", True, 100)

第二個(gè)按鈕

本文標(biāo)題:包含vb點(diǎn)虐 ftp類(lèi)的詞條
URL標(biāo)題:http://muchs.cn/article18/ddiiogp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供定制開(kāi)發(fā)、做網(wǎng)站、網(wǎng)站維護(hù)、響應(yīng)式網(wǎng)站云服務(wù)器、用戶(hù)體驗(yàn)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

綿陽(yáng)服務(wù)器托管