Upload 01
This commit is contained in:
155
FTPUpload/Form1.vb
Normal file
155
FTPUpload/Form1.vb
Normal file
@@ -0,0 +1,155 @@
|
||||
Imports System.IO.File
|
||||
Imports System.Net.Mail
|
||||
|
||||
Public Class Form1
|
||||
|
||||
Public sAppPath As String = Application.StartupPath
|
||||
Public parameter As String() = Environment.GetCommandLineArgs.ToArray()
|
||||
Public PDFUploadPath As String = ""
|
||||
|
||||
Public DatumNextMonday 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"
|
||||
|
||||
Private Function LoadParameters()
|
||||
Try
|
||||
Dim lines = IO.File.ReadAllLines(sAppPath.Substring(0, sAppPath.Length - 10) & "\start.ini")
|
||||
Dim colCount = lines.First.Split(";"c).Length
|
||||
|
||||
For Each line In lines
|
||||
Dim objFields = From field In line.Split(";"c)
|
||||
|
||||
Select Case objFields(0).ToString
|
||||
Case "PDFUploadPath"
|
||||
PDFUploadPath = objFields(1).ToString
|
||||
End Select
|
||||
|
||||
Next
|
||||
Catch ex As Exception
|
||||
MsgBox("FTPUpload: start.ini nicht gefunden!")
|
||||
End Try
|
||||
|
||||
End Function
|
||||
|
||||
Public Function Upload()
|
||||
If Silent = True Then
|
||||
DoUpload()
|
||||
Else
|
||||
If MsgBox("Achtung! Mit Bestätigen dieser Meldung wird das aktuelle Mittagsmenü auf der Homepage ÜBERSCHRIEBEN!", MsgBoxStyle.OkCancel, "Upload") = MsgBoxResult.Ok Then
|
||||
DoUpload()
|
||||
|
||||
Else
|
||||
Exit Function
|
||||
End If
|
||||
End If
|
||||
End Function
|
||||
|
||||
Function DoUpload()
|
||||
Dim anhang, anhangdateiname As String
|
||||
|
||||
If Exists(PDFUploadPath & DatumNextMonday & ".pdf") Then
|
||||
anhang = PDFUploadPath & DatumNextMonday & ".pdf"
|
||||
anhangdateiname = DatumNextMonday & ".pdf"
|
||||
Else
|
||||
If Silent = False Then
|
||||
MsgBox("Datei nicht gefunden. Bitte erst erstellen.") : Exit Function
|
||||
Else
|
||||
sendMail("FTP Upload fehlgeschlagen!", "Der automatische Upload wurde nicht ausgeführt. Datei: " & PDFUploadPath & DatumNextMonday & ".pdf wurde nicht gefunden.") : Exit Function
|
||||
End If
|
||||
End If
|
||||
|
||||
Upload2FTP(HighwayFTPSrv & "/speisekarte/Mittagsmenue.pdf", HighwayFTPUser, HighwayFTPPwd, anhang)
|
||||
End Function
|
||||
|
||||
|
||||
Public Function GetNextMonday()
|
||||
Dim datum As Date = Now.Date.AddDays(7)
|
||||
|
||||
For i = 0 To 10
|
||||
If datum.DayOfWeek = 1 Then
|
||||
Exit For
|
||||
Else
|
||||
datum = datum.AddDays(-1)
|
||||
End If
|
||||
Next
|
||||
DatumNextMonday = datum.Date.ToString.Substring(0, 10)
|
||||
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
|
||||
|
||||
' read in file...
|
||||
Dim bFile() As Byte = System.IO.File.ReadAllBytes(file)
|
||||
|
||||
' 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")
|
||||
|
||||
End Function
|
||||
|
||||
Private Sub btnUpload_Click(sender As Object, e As EventArgs) Handles btnUpload.Click
|
||||
GetNextMonday()
|
||||
Upload()
|
||||
End Sub
|
||||
|
||||
Private Sub bntUploadAndClose_Click(sender As Object, e As EventArgs) Handles bntUploadAndClose.Click
|
||||
GetNextMonday()
|
||||
Upload()
|
||||
Close()
|
||||
End Sub
|
||||
|
||||
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles Me.Load
|
||||
LoadParameters()
|
||||
|
||||
|
||||
For i = 0 To parameter.Length - 1
|
||||
Select Case parameter(i).ToString
|
||||
Case "/auto"
|
||||
' MsgBox("p")
|
||||
Silent = True
|
||||
bntUploadAndClose.PerformClick()
|
||||
End Select
|
||||
Next
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
Public Function sendMail(subject As String, body As String)
|
||||
Try
|
||||
Dim Smtp_Server As New SmtpClient
|
||||
Dim e_mail As New MailMessage()
|
||||
Smtp_Server.UseDefaultCredentials = False
|
||||
Smtp_Server.Credentials = New Net.NetworkCredential("monitoring@verag.com", "Ju18WA10")
|
||||
Smtp_Server.Port = 25
|
||||
Smtp_Server.EnableSsl = False
|
||||
Smtp_Server.Host = "owa.verag.ag"
|
||||
|
||||
e_mail = New MailMessage()
|
||||
e_mail.From = New MailAddress("monitoring@verag.com")
|
||||
e_mail.To.Add("monitoring@verag.com")
|
||||
' e_mail.Subject = "FTP Upload ausgeführt"
|
||||
e_mail.Subject = subject
|
||||
e_mail.IsBodyHtml = False
|
||||
'e_mail.Body = "Der automatische Upload wurde ausgeführt. Datei: " & PDFUploadPath & DatumNextMonday & ".pdf"
|
||||
e_mail.Body = body
|
||||
Smtp_Server.Send(e_mail)
|
||||
If Silent = False Then MsgBox("Mail Sent")
|
||||
|
||||
Catch error_t As Exception
|
||||
MsgBox(error_t.ToString)
|
||||
End Try
|
||||
End Function
|
||||
End Class
|
||||
Reference in New Issue
Block a user