diff --git a/09.12.2024.pdf b/09.12.2024.pdf new file mode 100644 index 0000000..408f5c3 Binary files /dev/null and b/09.12.2024.pdf differ diff --git a/FTPUpload/FTPUpload.vbproj b/FTPUpload/FTPUpload.vbproj index 49b9e19..336ca76 100644 --- a/FTPUpload/FTPUpload.vbproj +++ b/FTPUpload/FTPUpload.vbproj @@ -49,10 +49,41 @@ On + + ..\packages\BouncyCastle.Cryptography.2.4.0\lib\net461\BouncyCastle.Cryptography.dll + + + ..\packages\Microsoft.Bcl.AsyncInterfaces.1.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll + + + ..\packages\SSH.NET.2024.2.0\lib\net462\Renci.SshNet.dll + + + ..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + + ..\packages\System.Formats.Asn1.8.0.1\lib\net462\System.Formats.Asn1.dll + + + ..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + + + ..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\packages\System.Runtime.CompilerServices.Unsafe.4.5.3\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + ..\packages\System.Threading.Tasks.Extensions.4.5.2\lib\netstandard2.0\System.Threading.Tasks.Extensions.dll + + + ..\packages\System.ValueTuple.4.5.0\lib\net47\System.ValueTuple.dll + @@ -119,6 +150,7 @@ Settings.Designer.vb + diff --git a/FTPUpload/Form1.Designer.vb b/FTPUpload/Form1.Designer.vb index 0244ed9..f687c39 100644 --- a/FTPUpload/Form1.Designer.vb +++ b/FTPUpload/Form1.Designer.vb @@ -25,6 +25,7 @@ Partial Class Form1 Me.btnUpload = New System.Windows.Forms.Button() Me.bntUploadAndClose = New System.Windows.Forms.Button() Me.Button1 = New System.Windows.Forms.Button() + Me.Button2 = New System.Windows.Forms.Button() Me.SuspendLayout() ' 'btnUpload @@ -54,11 +55,21 @@ Partial Class Form1 Me.Button1.Text = "Do SQL!" Me.Button1.UseVisualStyleBackColor = True ' + 'Button2 + ' + Me.Button2.Location = New System.Drawing.Point(280, 362) + Me.Button2.Name = "Button2" + Me.Button2.Size = New System.Drawing.Size(200, 23) + Me.Button2.TabIndex = 3 + Me.Button2.Text = "Aktuelle überschreiben" + Me.Button2.UseVisualStyleBackColor = True + ' 'Form1 ' Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!) Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font Me.ClientSize = New System.Drawing.Size(800, 450) + Me.Controls.Add(Me.Button2) Me.Controls.Add(Me.Button1) Me.Controls.Add(Me.bntUploadAndClose) Me.Controls.Add(Me.btnUpload) @@ -71,4 +82,5 @@ Partial Class Form1 Friend WithEvents btnUpload As Button Friend WithEvents bntUploadAndClose As Button Friend WithEvents Button1 As Button + Friend WithEvents Button2 As Button End Class diff --git a/FTPUpload/Form1.vb b/FTPUpload/Form1.vb index ca6d062..e46577f 100644 --- a/FTPUpload/Form1.vb +++ b/FTPUpload/Form1.vb @@ -1,5 +1,7 @@ Imports System.IO.File Imports System.Net.Mail +Imports Renci.SshNet +Imports System.IO Public Class Form1 @@ -8,11 +10,12 @@ Public Class Form1 Public PDFUploadPath As String = "" Public DatumNextMonday As String + Public DatumThisWeeksMonday As String Public Silent As Boolean = False Public Shared HighwayFTPUser As String = "u78672691" - Public Shared HighwayFTPPwd As String = "verag#2" - Public Shared HighwayFTPSrv As String = "ftp://home546285429.1and1-data.host" + Public Shared HighwayFTPPwd As String = "LmZAK6x!Ur6^7BaUkCV^5Zk*G" + Public Shared HighwayFTPSrv As String = "home546285429.1and1-data.host" Private Function LoadParameters() Try @@ -61,7 +64,7 @@ Public Class Form1 End If End If - Upload2FTP(HighwayFTPSrv & "/speisekarte/Mittagsmenue.pdf", HighwayFTPUser, HighwayFTPPwd, anhang) + Upload2SFTP(HighwayFTPSrv, 22, HighwayFTPUser, HighwayFTPPwd, anhang) End Function @@ -79,25 +82,51 @@ Public Class Form1 Return (DatumNextMonday) End Function - Public Function Upload2FTP(server As String, user As String, pwd As String, file As String) - Dim clsRequest As System.Net.FtpWebRequest = - DirectCast(System.Net.WebRequest.Create(server), System.Net.FtpWebRequest) - clsRequest.Credentials = New System.Net.NetworkCredential(user, pwd) - clsRequest.Method = System.Net.WebRequestMethods.Ftp.UploadFile + Public Function GetThisWeeksMonday() + Dim datum As Date = Now.Date.AddDays(0) - ' read in file... - Dim bFile() As Byte = System.IO.File.ReadAllBytes(file) + For i = 0 To 10 + If datum.DayOfWeek = 1 Then + Exit For + Else + datum = datum.AddDays(-1) + End If + Next + DatumThisWeeksMonday = datum.Date.ToString.Substring(0, 10) + Return (DatumThisWeeksMonday) + End Function - ' upload file... - Dim clsStream As System.IO.Stream = - clsRequest.GetRequestStream() - clsStream.Write(bFile, 0, bFile.Length) - clsStream.Close() - clsStream.Dispose() - If Silent = False Then MsgBox("Ok, erledigt.") - sendMail("FTP Upload ausgeführt", "Der automatische Upload wurde ausgeführt. Datei: " & PDFUploadPath & DatumNextMonday & ".pdf") + Public Function Upload2SFTP(server As String, port As Integer, user As String, pwd As String, filePath As String, Optional Silent As Boolean = False) As Boolean + Try + ' Verbindung zu SFTP herstellen + Using sftpClient As New SftpClient(server, port, user, pwd) + sftpClient.Connect() + ' Datei einlesen + Dim fileBytes() As Byte = File.ReadAllBytes(filePath) + Dim remoteFileName As String = "/speisekarte/Mittagsmenue.pdf" 'Path.GetFileName(filePath) + + ' Datei hochladen + Using stream As New MemoryStream(fileBytes) + sftpClient.UploadFile(stream, remoteFileName) + End Using + + sftpClient.Disconnect() + End Using + + ' Rückmeldung und optional E-Mail + If Not Silent Then + MsgBox("Upload erfolgreich abgeschlossen.") + End If + sendMail("SFTP-Upload ausgeführt", $"Der automatische Upload wurde ausgeführt. Datei: {filePath}") + + Return True + Catch ex As Exception + ' Fehlerbehandlung + MsgBox("Fehler beim SFTP-Upload: " & ex.Message) + Return False + End Try End Function Private Sub btnUpload_Click(sender As Object, e As EventArgs) Handles btnUpload.Click @@ -135,7 +164,7 @@ Public Class Form1 Dim sql As New Gastro.cSQL Dim Upload2SQLGuide As String = "INSERT INTO [SQLGUIDE01.verag.ost.dmn].[AVISO].dbo.[tblEBMenu] -Select *, 5 as [MenuBestellungBisTageVorher] from [192.168.2.17].[Gastro].dbo.[GMenu] as table1 +Select *, 4 as [MenuBestellungBisTageVorher] from [192.168.2.17].[Gastro].dbo.[GMenu] as table1 WHERE NOT EXISTS ( select * from [SQLGUIDE01.verag.ost.dmn].[AVISO].dbo.[tblEBMenu] as table2 WHERE table1.MenuTitel = table2.MenuTitel AND table1.[MenuDateVon] = table2.[MenuDateVon] ) @@ -177,4 +206,10 @@ WHERE NOT EXISTS ( sqlsendinator() End Sub + + Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click + GetThisWeeksMonday() + DatumNextMonday = DatumThisWeeksMonday + Upload() + End Sub End Class diff --git a/FTPUpload/packages.config b/FTPUpload/packages.config new file mode 100644 index 0000000..80ae976 --- /dev/null +++ b/FTPUpload/packages.config @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/FTPUpload/start.ini b/FTPUpload/start.ini new file mode 100644 index 0000000..87872b8 --- /dev/null +++ b/FTPUpload/start.ini @@ -0,0 +1,2 @@ +DBConnection;Debug;--------------------------------------------------------Debug oder Highway; +PDFUploadPath;D:\repos\Gastro\FTPUpload\bin\Debug\Menues\;----------------Pfad für PDF Upload; \ No newline at end of file