Hi there!
I'm having a small problem with my coding. I am new to this level of VB coding, and coding in general really, the only coding I've ever done in VB is to make a simple login manager!
Anyway, I am getting the errors that are mentioned in the title. Here is my code:
Errors:
Identifier Expected (Line 143, Column 72)
Type Expected (Line 90, Column 24)
Any help will be appreciated! Thanks,
JJE990
I'm having a small problem with my coding. I am new to this level of VB coding, and coding in general really, the only coding I've ever done in VB is to make a simple login manager!
Anyway, I am getting the errors that are mentioned in the title. Here is my code:
Code:
Imports System.Net
Imports System.IO
Imports System.Security.Policy
Public Class Form1
Private Sub TabPage1_Click(sender As System.Object, e As System.EventArgs)
End Sub
Private Sub WebBrowser1_DocumentCompleted(sender As System.Object, e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub listFTP(ByVal URL As String, ByVal bk As String, ByVal pw As String)
Dim requ As FtpWebRequest = Nothing
Dim resp As FtpWebResponse = Nothing
Dim reader As StreamReader = Nothing
Try
requ = CType(WebRequest.Create(URL), WebRequest)
requ.Credentials = New NetworkCredential(bk, pw)
requ.Method = WebRequestMethods.Ftp.ListDirectory
resp = CType(requ.GetResponse(), FtpWebResponse)
reader = New StreamReader(resp.GetResponseStream())
While (reader.Peek() > -1)
ListBox1.Items.Add(reader.ReadLine())
End While
ToolStripStatusLabel1.Text = "Listing Complete!"
Catch ex As UriFormatException
ToolStripStatusLabel1.Text = ex.Message
Catch ex As WebException
ToolStripLabel2.Text = ex.Message
Finally
If reader IsNot Nothing Then reader.Close()
End Try
End Sub
Private Sub downloadFTP(ByVal URL As String, ByVal bk As String, ByVal pw As String)
Dim requ As FtpWebRequest = Nothing
Dim resp As FtpWebResponse = Nothing
Dim respStrm As Stream = Nothing
Dim fileStrm As FileStream = Nothing
Try
requ = CType(WebRequest.Create(URL), FtpWebRequest)
requ.Credentials = New NetworkCredential(bk, pw)
requ.Method = WebRequestMethods.Ftp.DownloadFile
resp = CType(requ.GetResponse(), FtpWebResponse)
respStrm = resp.GetResponseStream()
SaveFileDialog1.FileName = Path.GetFileName(requ.RequestUri.LocalPath)
If (SaveFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
fileStrm = File.Create(SaveFileDialog1.FileName)
Dim buff(1024) As Byte
Dim bytesRead As Integer = 0
While (True)
bytesRead = respStrm.Read(buff, 0, buff.Length)
If (bytesRead = 0) Then Exit While
fileStrm.Write(buff, 0, bytesRead)
End While
ToolStripStatusLabel1.Text = "Download Complete!"
End If
Catch ex As UriFormatException
ToolStripStatusLabel1.Text = ex.Message
Catch ex As WebException
ToolStripStatusLabel1.Text = ex.Message
Catch ex As IOException
ToolStripStatusLabel2.Text = ex.Message
Finally
If respStrm IsNot Nothing Then respStrm.Close()
If fileStrm IsNot Nothing Then fileStrm.Close()
End Try
End Sub
Private Sub uploadFTP(ByVal uri As String, ByVal filename As String, ByVal bk As String, ByVal pw As String)
Dim requ As FtpWebRequest = Nothing
Dim resp As FtpWebResponse = Nothing
Dim requStrm As Stream = Nothing
Dim fileStrm As FileStream = Nothing
Try
requ = CType(WebRequest.Create(Url), FtpWebRequest)
requ.Credentials = New NetworkCredential(bk, pw)
requ.Method = WebRequestMethods.Ftp.UploadFile
requ.Timeout = System.Threading.Timeout.Infinite
requ.Proxy = Nothing
requStrm = requ.GetRequestStream()
Dim buff As(2048) byte
Dim bytesread As Integer = 0
fileStrm = File.OpenRead(filename)
Do While (True)
bytesread = fileStrm.Read(buff, 0, buff.length)
If (bytesread = 0) Then Exit Do
requStrm.Write(buff, 0, bytesread)
Loop
requStrm.Close()
resp = CType(requ.GetResponse(), FtpWebResponse)
ToolStripLabel1.Text = "Upload Complete!"
Catch ex As UriFormatException
ToolStripStatusLabel1.Text = ex.Message
Catch ex As IOException
ToolStripStatusLabel2.Text = ex.Message
Catch ex As WebException
ToolStripLabel2.Text = ex.Message
Finally
If resp IsNot Nothing Then resp.Close()
If fileStrm IsNot Nothing Then fileStrm.Close()
If requStrm IsNot Nothing Then requStrm.Close()
End Try
End Sub
Private Sub deleteFTP(ByVal URL As String, ByVal bk As String, ByVal pw As String)
Dim requ As FtpWebRequest = Nothing
Dim resp As FtpWebResponse = Nothing
Try
requ = CType(WebRequest.Create(URL), FtpWebRequest)
requ.Credentials = New NetworkCredential(bk, pw)
requ.Method = WebRequestMethods.Ftp.DeleteFile
resp = CType(requ.GetResponse(), FtpWebResponse)
ToolStripStatusLabel1.Text = "File Deleted!"
Catch ex As UriFormatException
ToolStripStatusLabel1.Text = ex.Message
Catch ex As WebException
ToolStripStatusLabel2.Text = ex.Message
Finally
If resp IsNot Nothing Then resp.Close()
End Try
End Sub
Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
downloadFTP(TextBox4.Text, txt_user.Text, txt_pw.Text)
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
ListBox1.Items.Clear()
listFTP(txt_server.Text, txt_user.Text, txt_pw.Text)
End Sub
Private Sub ListBox1_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
TextBox4.Text = txt_server.Text & "/" & ListBox1.SelectedItems.(0).ToString()
End Sub
Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
If (OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK) Then
uploadFTP(OpenFileDialog1.FileName, txt_server.Text + "/" + Path.GetFileName(OpenFileDialog1.FileName), txt_user.Text, txt_pw.Text)
End If
End Sub
Private Sub Button4_Click(sender As System.Object, e As System.EventArgs) Handles Button4.Click
If (MessageBox.Show("Delete File?", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) = Windows.Forms.DialogResult.Yes) Then
deleteFTP(TextBox4.Text, txt_user.Text, txt_pw.Text)
End If
End Sub
Private Sub Button5_Click(sender As System.Object, e As System.EventArgs) Handles Button5.Click
ListBox1.Items.Clear()
listFTP(txt_server.Text, txt_user.Text, txt_pw.Text)
End Sub
Private Function Url() As String
Throw New NotImplementedException
End Function
Private Function buff() As Byte()
Throw New NotImplementedException
End Function
End Class
Errors:
Identifier Expected (Line 143, Column 72)
Type Expected (Line 90, Column 24)
Any help will be appreciated! Thanks,
JJE990