代码
1 Imports System
2 Imports System.IO
3 Imports System.Net
4 Imports System.Text
5 Public Class ftpUpload
6
7 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
8
9 Dim request As FtpWebRequest = DirectCast(WebRequest.Create("http://www.cnblogs.com/Believeme/admin/ftp://76.73.62.252/123.xml"), FtpWebRequest)
10 request.Method = WebRequestMethods.Ftp.UploadFile
11
12
13 request.Credentials = New NetworkCredential("3339", "libaoxin") '用户名,密码
14
15 Dim sourceStream As New StreamReader("D:\123.xml") '要上传的文件
16 Dim fileContents As Byte() = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd())
17 sourceStream.Close()
18 request.ContentLength = fileContents.Length
19 Dim requestStream As Stream = request.GetRequestStream()
20 requestStream.Write(fileContents, 0, fileContents.Length)
21 requestStream.Close()
22 Dim response As FtpWebResponse = DirectCast(request.GetResponse(), FtpWebResponse)
23 response.Close()
24 End Sub
25 End Class
26
27
28 附:http://msdn.microsoft.com/zh-cn/library/ms229715(VS.80).aspx
29
2 Imports System.IO
3 Imports System.Net
4 Imports System.Text
5 Public Class ftpUpload
6
7 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
8
9 Dim request As FtpWebRequest = DirectCast(WebRequest.Create("http://www.cnblogs.com/Believeme/admin/ftp://76.73.62.252/123.xml"), FtpWebRequest)
10 request.Method = WebRequestMethods.Ftp.UploadFile
11
12
13 request.Credentials = New NetworkCredential("3339", "libaoxin") '用户名,密码
14
15 Dim sourceStream As New StreamReader("D:\123.xml") '要上传的文件
16 Dim fileContents As Byte() = Encoding.UTF8.GetBytes(sourceStream.ReadToEnd())
17 sourceStream.Close()
18 request.ContentLength = fileContents.Length
19 Dim requestStream As Stream = request.GetRequestStream()
20 requestStream.Write(fileContents, 0, fileContents.Length)
21 requestStream.Close()
22 Dim response As FtpWebResponse = DirectCast(request.GetResponse(), FtpWebResponse)
23 response.Close()
24 End Sub
25 End Class
26
27
28 附:http://msdn.microsoft.com/zh-cn/library/ms229715(VS.80).aspx
29