Public Class Form1
Private Sub Btn_SendFtp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_SendFtp.Click
Try
'Create Request
Dim Request As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create("ftp://ftp.myweb.com/public_html/test.txt"), System.Net.FtpWebRequest)
'Upload Properties
Request.Credentials = New System.Net.NetworkCredential("user", "password")
Request.Method = System.Net.WebRequestMethods.Ftp.UploadFile
'Read File
Dim File() As Byte = System.IO.File.ReadAllBytes("c:\myfile.text")
'Upload
Dim Strz As System.IO.Stream = Request.GetRequestStream()
Strz.Write(File, 0, File.Length)
Strz.Close()
Strz.Dispose()
MessageBox.Show("Upload Done", "Messsage")
Catch ex As Exception
MessageBox.Show(ex.Message, "Messsage")
End Try
End Sub
Private Sub Btn_LoadFtp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_LoadFtp.Click
Try
My.Computer.Network.DownloadFile("http://www.myweb.com/test.txt", "c:\myfile_download.text")
'Process.Start("c:\myfile_download.text")'สั่งเปิดโปรแกรม
MessageBox.Show("Download Done", "Messsage")
Catch ex As Exception
MessageBox.Show(ex.Message, "Messsage")
End Try
End Sub
Private Sub Btn_DelFtp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Btn_DelFtp.Click
Try
'Create Request
Dim Request As System.Net.FtpWebRequest = DirectCast(System.Net.WebRequest.Create("ftp://ftp.myweb.com/public_html/test.txt"), System.Net.FtpWebRequest)
'Upload Properties
Request.Credentials = New System.Net.NetworkCredential("user", "password")
Request.Method = System.Net.WebRequestMethods.Ftp.DeleteFile
Request.GetResponse()
MessageBox.Show("Delete Done", "Messsage")
Catch ex As Exception
MessageBox.Show(ex.Message, "Messsage")
End Try
End Sub
End Class