Hallo,
Ich möchte ein FTP Explorer in ein Program einbauen aber habe leider Keine Ahnung wie.
Ich habe etwas im Inet gefunden aber es funktioniert leider nicht.
Hier:
Ich möchte ein FTP Explorer in ein Program einbauen aber habe leider Keine Ahnung wie.
Ich habe etwas im Inet gefunden aber es funktioniert leider nicht.
Hier:
Quellcode
- Imports System.Net
- Imports System.IO
- Public Class MainForm
- Private Sub MainForm_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- txtServer.Select()
- End Sub
- Private Sub btnLogin_Click(sender As Object, e As EventArgs) Handles btnLogin.Click
- tvServer.Nodes.Item(0).Collapse()
- LoadFTPRemote(txtServer.Text, tvServer)
- End Sub
- Public Sub LoadFTPRemote(ByVal dirpath As String, eTree As TreeView)
- eTree.Nodes.Item(0).Nodes.Clear()
- eTree.BeginUpdate()
- Dim request As FtpWebRequest = DirectCast(WebRequest.Create(dirpath), FtpWebRequest)
- request.Method = WebRequestMethods.Ftp.ListDirectory
- request.Credentials = New NetworkCredential(txtUsername.Text, txtPassword.Text)
- Dim response As FtpWebResponse = DirectCast(request.GetResponse(), FtpWebResponse)
- Dim responseStream As Stream = response.GetResponseStream()
- Dim reader As New StreamReader(responseStream)
- Do While reader.Peek() >= 0
- Dim nD As TreeNode = New TreeNode(reader.ReadLine())
- eTree.Nodes.Item(0).Nodes.Add(nD)
- Loop
- reader.Close()
- response.Close()
- eTree.Nodes.Item(0).Expand()
- eTree.EndUpdate()
- End Sub
- Private Sub tvServer_AfterExpand(sender As Object, e As TreeViewEventArgs) Handles tvServer.AfterExpand
- tvServer.BeginUpdate()
- Dim Node As TreeNode = e.Node
- For Each CNode As TreeNode In Node.Nodes
- Dim PathBuilder As String = txtServer.Text & ProperRemoteLink(CNode.FullPath)
- If Not Path.HasExtension(PathBuilder) Then
- CNode.Nodes.Clear()
- Dim request As FtpWebRequest = DirectCast(WebRequest.Create(PathBuilder), FtpWebRequest)
- request.Method = WebRequestMethods.Ftp.ListDirectory
- request.Credentials = New NetworkCredential(txtUsername.Text, txtPassword.Text)
- Dim response As FtpWebResponse = DirectCast(request.GetResponse(), FtpWebResponse)
- Dim responseStream As Stream = response.GetResponseStream()
- Dim reader As New StreamReader(responseStream)
- Dim strList As New List(Of String)
- Do While reader.Peek() >= 0
- Dim xNod As TreeNode = New TreeNode(IO.Path.GetFileName(reader.ReadLine()))
- CNode.Nodes.Add(xNod)
- Loop
- reader.Close()
- response.Close()
- End If
- Next
- tvServer.EndUpdate()
- End Sub
- Public Function ProperRemoteLink(ByVal input As String) As String
- Dim output As String = input
- If input.StartsWith("FTP Server") Then output = input.ToString.Remove(0, 10)
- Return output
- End Function
- Private Sub tvServer_AfterSelect(sender As Object, e As TreeViewEventArgs) Handles tvServer.AfterSelect
- lblStatus.Text = txtServer.Text & ProperRemoteLink(e.Node.FullPath)
- End Sub
- End Class