Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim root As New System.IO.DirectoryInfo(FolderBrowserDialog1.SelectedPath)
Dim ufiles() As System.IO.FileInfo = root.GetFiles
Timer1.Start()
For Each ufile As System.IO.FileInfo In ufiles
'Create Request
Dim Request As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create("ftp://" + FTPSettings.IP + "/" + "sawlibrary" + "/" +ufile.Name), System.Net.FtpWebRequest)
'Upload Properties
Request.Credentials = New System.Net.NetworkCredential(FTPSettings.UserID, FTPSettings.Password)
Request.Method = System.Net.WebRequestMethods.Ftp.UploadFile
'Read File
Dim File() As Byte = System.IO.File.ReadAllBytes(txtFile.Text + "\" + ufile.Name)
'Upload
Dim Strz As System.IO.Stream = Request.GetRequestStream()
Strz.Write(File, 0, File.Length)
Strz.Close()
Strz.Dispose()
Next
ProgressBar1.Increment(100)
If ProgressBar1.Value = ProgressBar1.Maximum Then
Timer1.Stop()
txtLink.Text = "ftp://" + FTPSettings.IP + "/" + "sawlibrary"
MsgBox("Save Complate!. Please your save")
End If
Catch ex As Exception
MessageBox.Show(ex.Message, "Messsage")
Exit Sub
End Try
End Sub
ส่วนดาวโหลด Code (VB.NET)
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Try
My.Computer.Network.DownloadFile("http://172.21.41.49/saw_library"+"/"+namefile, "c:\teeo\namefile")
MsgBox("done")
Catch ex As Exception
MessageBox.Show(ex.Message, "Messsage")
End Try
End Sub
Tag : .NET, MySQL, Win (Windows App), VB.NET, VS 2010 (.NET 4.x)
Dim fwr As Net.FtpWebRequest = Net.FtpWebRequest.Create("ftp://local.ftp.server")
fwr.Credentials = New NetworkCredential("user", "pass")
fwr.Method = WebRequestMethods.Ftp.ListDirectory
Using sr As New StreamReader(fwr.GetResponse().GetResponseStream())
Using sw As New StreamWriter("C:\Temp\FtpDir.txt", False)
sw.Write(sr.ReadToEnd())
End Using
End Using
fwr = Nothing