neu
This commit is contained in:
@@ -97,6 +97,9 @@ Public Class frmMDMNachrichtenVerarbeitung
|
||||
Function getNachrichtenDatenFromMDMServices() As Integer
|
||||
Dim cnt = 0
|
||||
Try
|
||||
|
||||
|
||||
|
||||
Dim MDM_server = ""
|
||||
Dim MDM_name = ""
|
||||
Dim MDM_pwd = ""
|
||||
@@ -105,24 +108,59 @@ Public Class frmMDMNachrichtenVerarbeitung
|
||||
|
||||
MDM_Worker.cMDMFunctions.getSFTPLoginData(MDM_server, MDM_name, MDM_pwd, MDM_port, "", MDM_PFAD_out)
|
||||
|
||||
Dim Dirlist As New List(Of String) 'I prefer List() instead of an array
|
||||
Dim request As FtpWebRequest = DirectCast(WebRequest.Create(MDM_server & MDM_PFAD_out), FtpWebRequest)
|
||||
|
||||
request.Method = WebRequestMethods.Ftp.ListDirectory
|
||||
request.Credentials = New NetworkCredential(MDM_name, MDM_pwd)
|
||||
DownloadFtpDirectory("ftp://ftp.plose.it" & "/"c & MDM_PFAD_out, New NetworkCredential(MDM_name, MDM_pwd), "", cnt, True)
|
||||
'Dim request = WebRequest.Create("ftp://ftp.plose.it" & "/"c & MDM_PFAD_out)
|
||||
''request.Method = WebRequestMethods.Ftp.DownloadFile
|
||||
''request.Credentials = New NetworkCredential(MDM_name, MDM_pwd)
|
||||
|
||||
Dim response As FtpWebResponse = DirectCast(request.GetResponse(), FtpWebResponse)
|
||||
Dim responseStream As Stream = response.GetResponseStream
|
||||
'request.Method = WebRequestMethods.Ftp.ListDirectory
|
||||
'request.Credentials = New NetworkCredential(MDM_name, MDM_pwd)
|
||||
|
||||
Using reader As New StreamReader(responseStream)
|
||||
Do While reader.Peek <> -1
|
||||
Dim fName = reader.ReadLine
|
||||
'Dim response As FtpWebResponse = DirectCast(request.GetResponse(), FtpWebResponse)
|
||||
'Dim responseStream As Stream = response.GetResponseStream
|
||||
|
||||
'Using reader As New StreamReader(responseStream)
|
||||
' Do While reader.Peek <> -1
|
||||
' Dim fName = reader.ReadLine
|
||||
|
||||
|
||||
Loop
|
||||
End Using
|
||||
' MsgBox(fName)
|
||||
' Loop
|
||||
'End Using
|
||||
|
||||
response.Close()
|
||||
' Dim dest = Path.Combine(MDM_PFAD_out, fileName)
|
||||
' Using resp = request.GetResponse(), strmResp = resp.GetResponseStream,
|
||||
'strmFile = New FileStream(dest, FileMode.Create)
|
||||
' Dim buf(1023) As Byte
|
||||
' Do
|
||||
' Dim read = strmResp.Read(buf, 0, buf.Length)
|
||||
' If read = 0 Then Exit Do 'end of Transmission
|
||||
' strmFile.Write(buf, 0, read)
|
||||
' Loop
|
||||
' End Using
|
||||
' Return False
|
||||
|
||||
|
||||
'MsgBox(MDM_server & "/" & MDM_PFAD_out)
|
||||
'Dim Dirlist As New List(Of String) 'I prefer List() instead of an array
|
||||
'Dim request As New FtpWebRequest("http://ftp.plose.it") ' DirectCast(WebRequest.Create("http://ftp.plose.it"), FtpWebRequest) ' DirectCast(WebRequest.Create("ftp.plose.it"), FtpWebRequest)
|
||||
|
||||
'request.Method = WebRequestMethods.Ftp.ListDirectory
|
||||
'request.Credentials = New NetworkCredential(MDM_name, MDM_pwd)
|
||||
|
||||
'Dim response As FtpWebResponse = DirectCast(request.GetResponse(), FtpWebResponse)
|
||||
'Dim responseStream As Stream = response.GetResponseStream
|
||||
|
||||
'Using reader As New StreamReader(responseStream)
|
||||
' Do While reader.Peek <> -1
|
||||
' Dim fName = reader.ReadLine
|
||||
|
||||
' MsgBox(fName)
|
||||
' Loop
|
||||
'End Using
|
||||
|
||||
'response.Close()
|
||||
|
||||
|
||||
|
||||
@@ -196,6 +234,87 @@ Public Class frmMDMNachrichtenVerarbeitung
|
||||
Return cnt
|
||||
End Function
|
||||
|
||||
Sub DownloadFtpDirectory(url As String, credentials As NetworkCredential, localPath As String, ByRef cnt As Integer, deleteAfterDownload As Boolean)
|
||||
Dim listRequest As FtpWebRequest = WebRequest.Create(url)
|
||||
listRequest.Method = WebRequestMethods.Ftp.ListDirectoryDetails
|
||||
listRequest.Credentials = credentials
|
||||
|
||||
|
||||
Dim lines As List(Of String) = New List(Of String)
|
||||
|
||||
Using listResponse As FtpWebResponse = listRequest.GetResponse(),
|
||||
listStream As Stream = listResponse.GetResponseStream(),
|
||||
listReader As StreamReader = New StreamReader(listStream)
|
||||
While Not listReader.EndOfStream
|
||||
lines.Add(listReader.ReadLine())
|
||||
End While
|
||||
End Using
|
||||
|
||||
For Each line As String In lines
|
||||
Dim tokens As String() =
|
||||
line.Split(New Char() {" "}, 9, StringSplitOptions.RemoveEmptyEntries)
|
||||
Dim name As String = tokens(8)
|
||||
Dim permissions As String = tokens(0)
|
||||
|
||||
Dim localFilePath As String = Path.Combine(localPath, name)
|
||||
Dim fileUrl As String = url + name
|
||||
|
||||
If permissions(0) = "d" Then
|
||||
If Not Directory.Exists(localFilePath) Then
|
||||
Directory.CreateDirectory(localFilePath)
|
||||
End If
|
||||
DownloadFtpDirectory(fileUrl + "/", credentials, localFilePath, cnt, deleteAfterDownload)
|
||||
|
||||
Else
|
||||
|
||||
If True Then
|
||||
' Temp.DownloadPfad
|
||||
Dim destFilenameTMP = VERARBEITUNGS_PFAD + "." & If(IO.File.Exists(VERARBEITUNGS_PFAD & "." & name), Now.ToString("yyMMdd_HHmmss.fff_"), "") & name
|
||||
|
||||
Dim downloadRequest As FtpWebRequest = WebRequest.Create(fileUrl)
|
||||
downloadRequest.Method = WebRequestMethods.Ftp.DownloadFile
|
||||
downloadRequest.Credentials = credentials
|
||||
|
||||
Using downloadResponse As FtpWebResponse = downloadRequest.GetResponse(),
|
||||
sourceStream As Stream = downloadResponse.GetResponseStream(),
|
||||
targetStream As Stream = File.OpenWrite(destFilenameTMP)
|
||||
Dim buffer As Byte() = New Byte(10240 - 1) {}
|
||||
Dim read As Integer
|
||||
Do
|
||||
read = sourceStream.Read(buffer, 0, buffer.Length)
|
||||
If read > 0 Then
|
||||
targetStream.Write(buffer, 0, read)
|
||||
End If
|
||||
Loop While read > 0
|
||||
|
||||
sourceStream.Dispose()
|
||||
targetStream.Dispose()
|
||||
downloadResponse.Dispose()
|
||||
|
||||
Dim destFilename = VERARBEITUNGS_PFAD & If(IO.File.Exists(VERARBEITUNGS_PFAD & name), Now.ToString("yyMMdd_HHmmss.fff_"), "") & name
|
||||
IO.File.Move(destFilenameTMP, destFilename) 'Datei umbenennen
|
||||
|
||||
|
||||
Dim fi As FileInfo = New FileInfo(destFilename)
|
||||
ListBox3.Items.Add(frmStartOptions.cut_file(fi.Name)) 'zur Liste hinzufügen
|
||||
cnt += 1
|
||||
|
||||
|
||||
'Datei nach download löschen
|
||||
If deleteAfterDownload Then
|
||||
Dim ftpReq As FtpWebRequest = WebRequest.Create(fileUrl)
|
||||
ftpReq.Method = WebRequestMethods.Ftp.DeleteFile
|
||||
ftpReq.Credentials = credentials
|
||||
Dim ftpResp As FtpWebResponse = ftpReq.GetResponse
|
||||
ftpResp.Close()
|
||||
End If
|
||||
|
||||
End Using
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
End Sub
|
||||
|
||||
|
||||
Function getNachrichtenDatenFromMDMServices_ALTERNATIV() As Integer
|
||||
Dim cnt = 0
|
||||
@@ -566,8 +685,8 @@ Public Class frmMDMNachrichtenVerarbeitung
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub pnl_Paint(sender As Object, e As PaintEventArgs) Handles pnl.Paint
|
||||
|
||||
|
||||
|
||||
End Sub
|
||||
End Class
|
||||
|
||||
|
||||
Reference in New Issue
Block a user