 |
|
ต้องการค้นหาใน directory ที่อยู่บน ftp server ว่ามีไฟล์อะไรบ้าง แสดงออกมาเป็นชื่อไปล์ ก็พอ |
|
 |
|
|
 |
 |
|
ตอนนี้ผมมีแต่การดาวโหลดได้ทีละไฟล์
แต่ผมอยากให้มัน ดาวโหลดทั้งหมดที่มีใน directory นี้ ftp://172.21.41.49/saw_library/...
ผมคิดว่าต้องมีการค้นหาไฟล์ที่มีทั้งหมดก่อน แล้วค่อยวนลูปทีละไฟล์
ในส่วนอัพโหลดผมก็ทำในลักษณะนี้เช่นกัน มีใครพอจะช่วยผมได้ไหมครับ
ส่วนอัพโหลด
Code (VB.NET)
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)
|
|
 |
 |
 |
 |
Date :
2012-06-18 13:02:29 |
By :
jet_program |
View :
1407 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
Code (VB.NET)
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
|
 |
 |
 |
 |
Date :
2012-06-18 21:00:33 |
By :
mr.win |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
โค้ดที่ให้มามัน list ออกมา แล้วมาสร้างเป็นเอกสารไม่ใช่หรือครับ
แล้วผมจะมาประยุกต์ใช้กับของผมยังไงเนี๊ย ช่วยเพิ่มเติมให้หน่อยนะครับ
เช่นแสดงออกมา เป็น msgbox ก็ยังดี ขอบคุณมากครับ
|
 |
 |
 |
 |
Date :
2012-06-19 10:21:45 |
By :
jet_program |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|