Klasse problem
Jeg har lavet en klasse(FtpDirectoryInfo) til at finde filer og mapper på en ftp server men GetDirectories funktionen virker ikke fordi den laver en array af FtpDirectoryInfo så være gang jeg setter et index så får Me den samme værdi, Hvordan undgår jeg det?.Code:
Imports System.IO
Imports System.Net
Public Class FtpFileInfo
Private Shared Username_, Password_, FullName_ As String
Public Sub New(ByVal Path As String, ByVal Username As String, ByVal Password As String)
FullName_ = Path
Username_ = Username
Password_ = Password
End Sub
Public ReadOnly Property FullName As String
Get
Return FullName_
End Get
End Property
Public ReadOnly Property Name As String
Get
Dim split() As String = FullName_.Split("/")
Return split(split.Length - 1)
End Get
End Property
Public ReadOnly Property Directory As FtpDirectoryInfo
Get
Return New FtpDirectoryInfo(Split(FullName_, "/" & Name)(0), Username_, Password_)
End Get
End Property
Public Function GetStream() As Stream
Dim a As FtpWebRequest = FtpWebRequest.Create(FullName)
a.Credentials = New NetworkCredential(Username_, Password_)
a.Method = WebRequestMethods.Ftp.DownloadFile
Return a.GetResponse.GetResponseStream
End Function
Public Overrides Function ToString() As String
Return FullName_
End Function
End Class
Public Class FtpDirectoryInfo
Private Shared Username_, Password_, FullName_ As String
Private Class ty
Public Shared Function GetNewFtpDirectoryInfo(ByVal Path As String, ByVal Username As String, ByVal Password As String)
Return New FtpDirectoryInfo(Path, Username, Password)
End Function
End Class
Public Sub New(ByVal Path As String, ByVal Username As String, ByVal Password As String)
FullName_ = Path
Username_ = Username
Password_ = Password
End Sub
Public ReadOnly Property FullName As String
Get
Return FullName_
End Get
End Property
Public ReadOnly Property Name As String
Get
Dim split() As String = FullName_.Split("/")
Return split(split.Length - 1)
End Get
End Property
Public ReadOnly Property Directory As FtpDirectoryInfo
Get
Return New FtpDirectoryInfo(Split(FullName_, "/" & Name)(0), Username_, Password_)
End Get
End Property
Public Function GetDirectories() As FtpDirectoryInfo()
Dim a As FtpWebRequest = FtpWebRequest.Create("ftp://ftp.madshaupt.dk/")
a.Credentials = New NetworkCredential(Username_, Password_)
a.Method = WebRequestMethods.Ftp.ListDirectoryDetails
Dim strs() As String = New StreamReader(a.GetResponse.GetResponseStream).ReadToEnd.Split(vbNewLine)
Dim dirslength As Integer = 0
For i = 0 To strs.Length - 1
If Split(strs(i), "drwxr-xr-x").Length = 2 Then
dirslength += 1
End If
Next
Dim dirs(dirslength) As FtpDirectoryInfo
Dim i2 As Integer = 0
For i = 0 To strs.Length - 1
If Split(strs(i), "drwxr-xr-x").Length = 2 Then
dirs(i2) = New FtpDirectoryInfo(FullName_ & strs(i).Split(":")(1).Substring(3), Username_, Password_)
i2 += 1
End If
Next
Return dirs
End Function
Public Function GetFiles() As FtpFileInfo()
Dim a As FtpWebRequest = FtpWebRequest.Create("ftp://ftp.madshaupt.dk/")
a.Credentials = New NetworkCredential(Username_, Password_)
a.Method = WebRequestMethods.Ftp.ListDirectoryDetails
Dim strs() As String = New StreamReader(a.GetResponse.GetResponseStream).ReadToEnd.Split(vbNewLine)
Dim fileslength As Integer = 0
For i = 0 To strs.Length - 1
If Split(strs(i), "-rwxr-xr-x").Length = 2 Then
fileslength += 1
End If
Next
Dim files(fileslength) As FtpFileInfo
Dim i2 As Integer = 0
For i = 0 To strs.Length - 1
If Split(strs(i), "-rwxr-xr-x").Length = 2 Then
i2 += 1
Dim Str As String = strs(i).Split(":")(1)
files(i2) = New FtpFileInfo(FullName_ & Str.Substring(2, Str.Length - 2).Substring(1, Str.Length - 3) & "/", Username_, Password_)
End If
Next
Return files
End Function
Public Shared Function GetFiles(ByVal Ftp As String, ByVal FileDirInfo As String, ByVal Username As String, ByVal Password As String) As FtpFileInfo()
Dim strs() As String = FileDirInfo.Split(vbNewLine)
Dim fileslength As Integer = 0
For i = 0 To strs.Length - 1
If Split(strs(i), "-rwxr-xr-x").Length = 2 Then
fileslength += 1
End If
Next
Dim files(fileslength) As FtpFileInfo
Dim i2 As Integer = 0
For i = 0 To strs.Length - 1
If Split(strs(i), "-rwxr-xr-x").Length = 2 Then
i2 += 1
Dim Str As String = strs(i).Split(":")(1)
files(i2) = New FtpFileInfo(Ftp & Str.Substring(2, Str.Length - 2).Substring(1, Str.Length - 3) & "/", Username, Password)
End If
Next
Return files
End Function
Public Shared Function GetDirectories(ByVal Ftp As String, ByVal FileDirInfo As String, ByVal Username As String, ByVal Password As String) As FtpDirectoryInfo()
Dim strs() As String = FileDirInfo.Split(vbNewLine)
Dim dirslength As Integer = 0
For i = 0 To strs.Length - 1
If Split(strs(i), "drwxr-xr-x").Length = 2 Then
dirslength += 1
End If
Next
Dim dirs(dirslength - 1) As FtpDirectoryInfo
Dim i2 As Integer = 0
For i = 0 To strs.Length - 1
If Split(strs(i), "drwxr-xr-x").Length = 2 Then
Dim Str As String = strs(i).Split(":")(1)
dirs(i2) = New FtpDirectoryInfo(Ftp & Str.Substring(2, Str.Length - 2).Substring(1, Str.Length - 3) & "/", Username, Password)
i2 += 1
End If
Next
Return dirs
End Function
Public Overrides Function ToString() As String
Return FullName_
End Function
End Class