Click here to Skip to main content
15,896,557 members
Articles / Programming Languages / Visual Basic

Building Client/Server applications with VB.NET for secure private file sharing

Rate me:
Please Sign up or sign in to vote.
3.70/5 (13 votes)
24 Nov 20057 min read 192.1K   15.6K   65  
How to build secure private file sharing client/server using a freeware SDK
'Visual Basic .NET example of secure file sharing client
'To keep this VB .NET example simple, we are going to implement
'only the main file operations



Option Strict Off
Option Explicit On
Friend Class CFrmMain
  Inherits System.Windows.Forms.Form
#Region "Windows Form Designer generated code "
  Public Sub New()
    MyBase.New()

    'This call is required by the Windows Form Designer.
    InitializeComponent()
  End Sub
  'Form overrides dispose to clean up the component list.
  Protected Overloads Overrides Sub Dispose(ByVal Disposing As Boolean)
    If Disposing Then
      If Not components Is Nothing Then
        components.Dispose()
      End If
    End If
    MyBase.Dispose(Disposing)
  End Sub
  'Required by the Windows Form Designer
  Private components As System.ComponentModel.IContainer
  Public ToolTip1 As System.Windows.Forms.ToolTip
  Public WithEvents helper As System.Windows.Forms.Button
  'NOTE: The following procedure is required by the Windows Form Designer
  'It can be modified using the Windows Form Designer.
  'Do not modify it using the code editor.
  Friend WithEvents StatusBar As System.Windows.Forms.StatusBar
  Friend WithEvents StatusBarPanel1 As System.Windows.Forms.StatusBarPanel
  Friend WithEvents StatusBarPanel2 As System.Windows.Forms.StatusBarPanel
  Friend WithEvents StatusBarPanel3 As System.Windows.Forms.StatusBarPanel
  Public WithEvents Frame2 As System.Windows.Forms.GroupBox
  Public WithEvents btnExit As System.Windows.Forms.Button
  Public WithEvents btnDisconnect As System.Windows.Forms.Button
  Public WithEvents btnCancel As System.Windows.Forms.Button
  Public WithEvents btnConnect As System.Windows.Forms.Button
  Public WithEvents Frame1 As System.Windows.Forms.GroupBox
  Public WithEvents btnRename As System.Windows.Forms.Button
  Public WithEvents btnDelete As System.Windows.Forms.Button
  Public WithEvents btnUpload As System.Windows.Forms.Button
  Public WithEvents btnDownload As System.Windows.Forms.Button
  Public WithEvents btnNew As System.Windows.Forms.Button
  Public WithEvents btnUp As System.Windows.Forms.Button
  Public WithEvents btnIn As System.Windows.Forms.Button
  Public WithEvents txtFolder As System.Windows.Forms.TextBox
  Public WithEvents btnList As System.Windows.Forms.Button
  Friend WithEvents ColumnHeader1 As System.Windows.Forms.ColumnHeader
  Friend WithEvents ColumnHeader2 As System.Windows.Forms.ColumnHeader
  Friend WithEvents ColumnHeader3 As System.Windows.Forms.ColumnHeader
  Public WithEvents Frame6 As System.Windows.Forms.GroupBox
  Public WithEvents txtDownload As System.Windows.Forms.TextBox
  Public WithEvents btnAbortDnld As System.Windows.Forms.Button
  Public WithEvents Frame5 As System.Windows.Forms.GroupBox
  Public WithEvents btnAbortUpld As System.Windows.Forms.Button
  Public WithEvents txtUpload As System.Windows.Forms.TextBox
  Friend WithEvents lvFiles As System.Windows.Forms.ListView
  Friend WithEvents ImageList1 As System.Windows.Forms.ImageList
  Friend WithEvents OpenDlg As System.Windows.Forms.OpenFileDialog
  Friend WithEvents SaveDlg As System.Windows.Forms.SaveFileDialog
  Friend WithEvents FileCln As AxbsFileClientSDK.AxBSFileClnX
  <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(CFrmMain))
Me.ToolTip1 = New System.Windows.Forms.ToolTip(Me.components)
Me.helper = New System.Windows.Forms.Button
Me.StatusBar = New System.Windows.Forms.StatusBar
Me.StatusBarPanel1 = New System.Windows.Forms.StatusBarPanel
Me.StatusBarPanel2 = New System.Windows.Forms.StatusBarPanel
Me.StatusBarPanel3 = New System.Windows.Forms.StatusBarPanel
Me.Frame2 = New System.Windows.Forms.GroupBox
Me.btnExit = New System.Windows.Forms.Button
Me.btnDisconnect = New System.Windows.Forms.Button
Me.btnCancel = New System.Windows.Forms.Button
Me.btnConnect = New System.Windows.Forms.Button
Me.Frame1 = New System.Windows.Forms.GroupBox
Me.FileCln = New AxBSFileClientSDK.AxBSFileClnX
Me.lvFiles = New System.Windows.Forms.ListView
Me.ColumnHeader1 = New System.Windows.Forms.ColumnHeader
Me.ColumnHeader2 = New System.Windows.Forms.ColumnHeader
Me.ColumnHeader3 = New System.Windows.Forms.ColumnHeader
Me.ImageList1 = New System.Windows.Forms.ImageList(Me.components)
Me.btnRename = New System.Windows.Forms.Button
Me.btnDelete = New System.Windows.Forms.Button
Me.btnUpload = New System.Windows.Forms.Button
Me.btnDownload = New System.Windows.Forms.Button
Me.btnNew = New System.Windows.Forms.Button
Me.btnUp = New System.Windows.Forms.Button
Me.btnIn = New System.Windows.Forms.Button
Me.txtFolder = New System.Windows.Forms.TextBox
Me.btnList = New System.Windows.Forms.Button
Me.Frame6 = New System.Windows.Forms.GroupBox
Me.txtDownload = New System.Windows.Forms.TextBox
Me.btnAbortDnld = New System.Windows.Forms.Button
Me.Frame5 = New System.Windows.Forms.GroupBox
Me.btnAbortUpld = New System.Windows.Forms.Button
Me.txtUpload = New System.Windows.Forms.TextBox
Me.OpenDlg = New System.Windows.Forms.OpenFileDialog
Me.SaveDlg = New System.Windows.Forms.SaveFileDialog
CType(Me.StatusBarPanel1, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.StatusBarPanel2, System.ComponentModel.ISupportInitialize).BeginInit()
CType(Me.StatusBarPanel3, System.ComponentModel.ISupportInitialize).BeginInit()
Me.Frame2.SuspendLayout()
Me.Frame1.SuspendLayout()
CType(Me.FileCln, System.ComponentModel.ISupportInitialize).BeginInit()
Me.Frame6.SuspendLayout()
Me.Frame5.SuspendLayout()
Me.SuspendLayout()
'
'helper
'
Me.helper.BackColor = System.Drawing.SystemColors.Control
Me.helper.Cursor = System.Windows.Forms.Cursors.Default
Me.helper.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.helper.ForeColor = System.Drawing.SystemColors.ControlText
Me.helper.Location = New System.Drawing.Point(-159, 451)
Me.helper.Name = "helper"
Me.helper.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.helper.Size = New System.Drawing.Size(135, 21)
Me.helper.TabIndex = 8
Me.helper.Text = "Command1"
'
'StatusBar
'
Me.StatusBar.Location = New System.Drawing.Point(0, 481)
Me.StatusBar.Name = "StatusBar"
Me.StatusBar.Panels.AddRange(New System.Windows.Forms.StatusBarPanel() {Me.StatusBarPanel1, Me.StatusBarPanel2, Me.StatusBarPanel3})
Me.StatusBar.ShowPanels = True
Me.StatusBar.Size = New System.Drawing.Size(690, 22)
Me.StatusBar.SizingGrip = False
Me.StatusBar.TabIndex = 23
Me.StatusBar.Text = "StatusBar1"
'
'StatusBarPanel1
'
Me.StatusBarPanel1.Width = 150
'
'StatusBarPanel2
'
Me.StatusBarPanel2.Width = 150
'
'StatusBarPanel3
'
Me.StatusBarPanel3.Width = 1500
'
'Frame2
'
Me.Frame2.BackColor = System.Drawing.SystemColors.Control
Me.Frame2.Controls.Add(Me.btnExit)
Me.Frame2.Controls.Add(Me.btnDisconnect)
Me.Frame2.Controls.Add(Me.btnCancel)
Me.Frame2.Controls.Add(Me.btnConnect)
Me.Frame2.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Frame2.ForeColor = System.Drawing.SystemColors.ControlText
Me.Frame2.Location = New System.Drawing.Point(7, -3)
Me.Frame2.Name = "Frame2"
Me.Frame2.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Frame2.Size = New System.Drawing.Size(671, 49)
Me.Frame2.TabIndex = 25
Me.Frame2.TabStop = False
'
'btnExit
'
Me.btnExit.BackColor = System.Drawing.SystemColors.Control
Me.btnExit.Cursor = System.Windows.Forms.Cursors.Default
Me.btnExit.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnExit.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnExit.Location = New System.Drawing.Point(295, 16)
Me.btnExit.Name = "btnExit"
Me.btnExit.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnExit.Size = New System.Drawing.Size(88, 26)
Me.btnExit.TabIndex = 16
Me.btnExit.Text = "Exit"
'
'btnDisconnect
'
Me.btnDisconnect.BackColor = System.Drawing.SystemColors.Control
Me.btnDisconnect.Cursor = System.Windows.Forms.Cursors.Default
Me.btnDisconnect.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnDisconnect.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnDisconnect.Location = New System.Drawing.Point(200, 16)
Me.btnDisconnect.Name = "btnDisconnect"
Me.btnDisconnect.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnDisconnect.Size = New System.Drawing.Size(88, 26)
Me.btnDisconnect.TabIndex = 15
Me.btnDisconnect.Text = "Disconnect"
'
'btnCancel
'
Me.btnCancel.BackColor = System.Drawing.SystemColors.Control
Me.btnCancel.Cursor = System.Windows.Forms.Cursors.Default
Me.btnCancel.Enabled = False
Me.btnCancel.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnCancel.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnCancel.Location = New System.Drawing.Point(106, 16)
Me.btnCancel.Name = "btnCancel"
Me.btnCancel.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnCancel.Size = New System.Drawing.Size(88, 26)
Me.btnCancel.TabIndex = 14
Me.btnCancel.Text = "Cancel"
'
'btnConnect
'
Me.btnConnect.BackColor = System.Drawing.SystemColors.Control
Me.btnConnect.Cursor = System.Windows.Forms.Cursors.Default
Me.btnConnect.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnConnect.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnConnect.Location = New System.Drawing.Point(12, 16)
Me.btnConnect.Name = "btnConnect"
Me.btnConnect.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnConnect.Size = New System.Drawing.Size(88, 26)
Me.btnConnect.TabIndex = 13
Me.btnConnect.Text = "Connect"
'
'Frame1
'
Me.Frame1.BackColor = System.Drawing.SystemColors.Control
Me.Frame1.Controls.Add(Me.FileCln)
Me.Frame1.Controls.Add(Me.lvFiles)
Me.Frame1.Controls.Add(Me.btnRename)
Me.Frame1.Controls.Add(Me.btnDelete)
Me.Frame1.Controls.Add(Me.btnUpload)
Me.Frame1.Controls.Add(Me.btnDownload)
Me.Frame1.Controls.Add(Me.btnNew)
Me.Frame1.Controls.Add(Me.btnUp)
Me.Frame1.Controls.Add(Me.btnIn)
Me.Frame1.Controls.Add(Me.txtFolder)
Me.Frame1.Controls.Add(Me.btnList)
Me.Frame1.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Frame1.ForeColor = System.Drawing.SystemColors.ControlText
Me.Frame1.Location = New System.Drawing.Point(8, 56)
Me.Frame1.Name = "Frame1"
Me.Frame1.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Frame1.Size = New System.Drawing.Size(671, 278)
Me.Frame1.TabIndex = 26
Me.Frame1.TabStop = False
Me.Frame1.Text = "Remote Files"
'
'FileCln
'
Me.FileCln.ContainingControl = Me
Me.FileCln.Location = New System.Drawing.Point(128, 208)
Me.FileCln.Name = "FileCln"
Me.FileCln.OcxState = CType(resources.GetObject("FileCln.OcxState"), System.Windows.Forms.AxHost.State)
Me.FileCln.Size = New System.Drawing.Size(287, 24)
Me.FileCln.TabIndex = 26
'
'lvFiles
'
Me.lvFiles.Columns.AddRange(New System.Windows.Forms.ColumnHeader() {Me.ColumnHeader1, Me.ColumnHeader2, Me.ColumnHeader3})
Me.lvFiles.Enabled = False
Me.lvFiles.FullRowSelect = True
Me.lvFiles.HideSelection = False
Me.lvFiles.Location = New System.Drawing.Point(112, 56)
Me.lvFiles.MultiSelect = False
Me.lvFiles.Name = "lvFiles"
Me.lvFiles.Size = New System.Drawing.Size(552, 200)
Me.lvFiles.SmallImageList = Me.ImageList1
Me.lvFiles.TabIndex = 25
Me.lvFiles.View = System.Windows.Forms.View.Details
'
'ColumnHeader1
'
Me.ColumnHeader1.Text = "Name"
Me.ColumnHeader1.Width = 199
'
'ColumnHeader2
'
Me.ColumnHeader2.Text = "Size"
Me.ColumnHeader2.TextAlign = System.Windows.Forms.HorizontalAlignment.Right
Me.ColumnHeader2.Width = 149
'
'ColumnHeader3
'
Me.ColumnHeader3.Text = "Time"
Me.ColumnHeader3.Width = 149
'
'ImageList1
'
Me.ImageList1.ImageSize = New System.Drawing.Size(16, 16)
Me.ImageList1.ImageStream = CType(resources.GetObject("ImageList1.ImageStream"), System.Windows.Forms.ImageListStreamer)
Me.ImageList1.TransparentColor = System.Drawing.Color.Magenta
'
'btnRename
'
Me.btnRename.BackColor = System.Drawing.SystemColors.Control
Me.btnRename.Cursor = System.Windows.Forms.Cursors.Default
Me.btnRename.Enabled = False
Me.btnRename.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnRename.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnRename.Location = New System.Drawing.Point(11, 203)
Me.btnRename.Name = "btnRename"
Me.btnRename.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnRename.Size = New System.Drawing.Size(88, 26)
Me.btnRename.TabIndex = 24
Me.btnRename.Text = "Rename"
'
'btnDelete
'
Me.btnDelete.BackColor = System.Drawing.SystemColors.Control
Me.btnDelete.Cursor = System.Windows.Forms.Cursors.Default
Me.btnDelete.Enabled = False
Me.btnDelete.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnDelete.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnDelete.Location = New System.Drawing.Point(11, 232)
Me.btnDelete.Name = "btnDelete"
Me.btnDelete.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnDelete.Size = New System.Drawing.Size(88, 26)
Me.btnDelete.TabIndex = 23
Me.btnDelete.Text = "Delete"
'
'btnUpload
'
Me.btnUpload.BackColor = System.Drawing.SystemColors.Control
Me.btnUpload.Cursor = System.Windows.Forms.Cursors.Default
Me.btnUpload.Enabled = False
Me.btnUpload.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnUpload.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnUpload.Location = New System.Drawing.Point(11, 173)
Me.btnUpload.Name = "btnUpload"
Me.btnUpload.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnUpload.Size = New System.Drawing.Size(88, 26)
Me.btnUpload.TabIndex = 22
Me.btnUpload.Text = "Upload"
'
'btnDownload
'
Me.btnDownload.BackColor = System.Drawing.SystemColors.Control
Me.btnDownload.Cursor = System.Windows.Forms.Cursors.Default
Me.btnDownload.Enabled = False
Me.btnDownload.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnDownload.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnDownload.Location = New System.Drawing.Point(11, 144)
Me.btnDownload.Name = "btnDownload"
Me.btnDownload.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnDownload.Size = New System.Drawing.Size(88, 26)
Me.btnDownload.TabIndex = 21
Me.btnDownload.Text = "Download"
'
'btnNew
'
Me.btnNew.BackColor = System.Drawing.SystemColors.Control
Me.btnNew.Cursor = System.Windows.Forms.Cursors.Default
Me.btnNew.Enabled = False
Me.btnNew.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnNew.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnNew.Location = New System.Drawing.Point(11, 108)
Me.btnNew.Name = "btnNew"
Me.btnNew.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnNew.Size = New System.Drawing.Size(88, 26)
Me.btnNew.TabIndex = 20
Me.btnNew.Text = "New Folder"
'
'btnUp
'
Me.btnUp.BackColor = System.Drawing.SystemColors.Control
Me.btnUp.Cursor = System.Windows.Forms.Cursors.Default
Me.btnUp.Enabled = False
Me.btnUp.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnUp.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnUp.Location = New System.Drawing.Point(11, 79)
Me.btnUp.Name = "btnUp"
Me.btnUp.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnUp.Size = New System.Drawing.Size(88, 26)
Me.btnUp.TabIndex = 19
Me.btnUp.Text = "Go Up"
'
'btnIn
'
Me.btnIn.BackColor = System.Drawing.SystemColors.Control
Me.btnIn.Cursor = System.Windows.Forms.Cursors.Default
Me.btnIn.Enabled = False
Me.btnIn.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnIn.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnIn.Location = New System.Drawing.Point(11, 50)
Me.btnIn.Name = "btnIn"
Me.btnIn.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnIn.Size = New System.Drawing.Size(88, 26)
Me.btnIn.TabIndex = 18
Me.btnIn.Text = "Go In"
'
'txtFolder
'
Me.txtFolder.AcceptsReturn = True
Me.txtFolder.AutoSize = False
Me.txtFolder.BackColor = System.Drawing.SystemColors.Menu
Me.txtFolder.Cursor = System.Windows.Forms.Cursors.IBeam
Me.txtFolder.Enabled = False
Me.txtFolder.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.txtFolder.ForeColor = System.Drawing.SystemColors.WindowText
Me.txtFolder.Location = New System.Drawing.Point(112, 22)
Me.txtFolder.MaxLength = 0
Me.txtFolder.Name = "txtFolder"
Me.txtFolder.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.txtFolder.Size = New System.Drawing.Size(552, 23)
Me.txtFolder.TabIndex = 17
Me.txtFolder.Text = ""
'
'btnList
'
Me.btnList.BackColor = System.Drawing.SystemColors.Control
Me.btnList.Cursor = System.Windows.Forms.Cursors.Default
Me.btnList.Enabled = False
Me.btnList.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnList.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnList.Location = New System.Drawing.Point(11, 21)
Me.btnList.Name = "btnList"
Me.btnList.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnList.Size = New System.Drawing.Size(88, 26)
Me.btnList.TabIndex = 1
Me.btnList.Text = "Refresh"
'
'Frame6
'
Me.Frame6.BackColor = System.Drawing.SystemColors.Control
Me.Frame6.Controls.Add(Me.txtDownload)
Me.Frame6.Controls.Add(Me.btnAbortDnld)
Me.Frame6.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Frame6.ForeColor = System.Drawing.SystemColors.ControlText
Me.Frame6.Location = New System.Drawing.Point(8, 352)
Me.Frame6.Name = "Frame6"
Me.Frame6.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Frame6.Size = New System.Drawing.Size(672, 49)
Me.Frame6.TabIndex = 27
Me.Frame6.TabStop = False
Me.Frame6.Text = "Download"
'
'txtDownload
'
Me.txtDownload.AcceptsReturn = True
Me.txtDownload.AutoSize = False
Me.txtDownload.BackColor = System.Drawing.SystemColors.ScrollBar
Me.txtDownload.Cursor = System.Windows.Forms.Cursors.IBeam
Me.txtDownload.Enabled = False
Me.txtDownload.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.txtDownload.ForeColor = System.Drawing.SystemColors.WindowText
Me.txtDownload.Location = New System.Drawing.Point(10, 18)
Me.txtDownload.MaxLength = 0
Me.txtDownload.Name = "txtDownload"
Me.txtDownload.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.txtDownload.Size = New System.Drawing.Size(565, 23)
Me.txtDownload.TabIndex = 10
Me.txtDownload.Text = ""
'
'btnAbortDnld
'
Me.btnAbortDnld.BackColor = System.Drawing.SystemColors.Control
Me.btnAbortDnld.Cursor = System.Windows.Forms.Cursors.Default
Me.btnAbortDnld.Enabled = False
Me.btnAbortDnld.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnAbortDnld.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnAbortDnld.Location = New System.Drawing.Point(584, 16)
Me.btnAbortDnld.Name = "btnAbortDnld"
Me.btnAbortDnld.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnAbortDnld.Size = New System.Drawing.Size(78, 26)
Me.btnAbortDnld.TabIndex = 9
Me.btnAbortDnld.Text = "Abort"
'
'Frame5
'
Me.Frame5.BackColor = System.Drawing.SystemColors.Control
Me.Frame5.Controls.Add(Me.btnAbortUpld)
Me.Frame5.Controls.Add(Me.txtUpload)
Me.Frame5.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.Frame5.ForeColor = System.Drawing.SystemColors.ControlText
Me.Frame5.Location = New System.Drawing.Point(8, 416)
Me.Frame5.Name = "Frame5"
Me.Frame5.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.Frame5.Size = New System.Drawing.Size(671, 49)
Me.Frame5.TabIndex = 28
Me.Frame5.TabStop = False
Me.Frame5.Text = "Upload"
'
'btnAbortUpld
'
Me.btnAbortUpld.BackColor = System.Drawing.SystemColors.Control
Me.btnAbortUpld.Cursor = System.Windows.Forms.Cursors.Default
Me.btnAbortUpld.Enabled = False
Me.btnAbortUpld.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.btnAbortUpld.ForeColor = System.Drawing.SystemColors.ControlText
Me.btnAbortUpld.Location = New System.Drawing.Point(583, 16)
Me.btnAbortUpld.Name = "btnAbortUpld"
Me.btnAbortUpld.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.btnAbortUpld.Size = New System.Drawing.Size(78, 26)
Me.btnAbortUpld.TabIndex = 7
Me.btnAbortUpld.Text = "Abort"
'
'txtUpload
'
Me.txtUpload.AcceptsReturn = True
Me.txtUpload.AutoSize = False
Me.txtUpload.BackColor = System.Drawing.SystemColors.ScrollBar
Me.txtUpload.Cursor = System.Windows.Forms.Cursors.IBeam
Me.txtUpload.Enabled = False
Me.txtUpload.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.txtUpload.ForeColor = System.Drawing.SystemColors.WindowText
Me.txtUpload.Location = New System.Drawing.Point(9, 18)
Me.txtUpload.MaxLength = 0
Me.txtUpload.Name = "txtUpload"
Me.txtUpload.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.txtUpload.Size = New System.Drawing.Size(566, 23)
Me.txtUpload.TabIndex = 6
Me.txtUpload.Text = ""
'
'CFrmMain
'
Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)
Me.BackColor = System.Drawing.SystemColors.Control
Me.ClientSize = New System.Drawing.Size(690, 503)
Me.Controls.Add(Me.Frame5)
Me.Controls.Add(Me.Frame6)
Me.Controls.Add(Me.Frame1)
Me.Controls.Add(Me.Frame2)
Me.Controls.Add(Me.StatusBar)
Me.Controls.Add(Me.helper)
Me.Cursor = System.Windows.Forms.Cursors.Default
Me.Font = New System.Drawing.Font("Arial", 8.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog
Me.Location = New System.Drawing.Point(4, 28)
Me.MaximizeBox = False
Me.MinimizeBox = False
Me.Name = "CFrmMain"
Me.RightToLeft = System.Windows.Forms.RightToLeft.No
Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
Me.Text = "Secure File Sharing Client"
CType(Me.StatusBarPanel1, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.StatusBarPanel2, System.ComponentModel.ISupportInitialize).EndInit()
CType(Me.StatusBarPanel3, System.ComponentModel.ISupportInitialize).EndInit()
Me.Frame2.ResumeLayout(False)
Me.Frame1.ResumeLayout(False)
CType(Me.FileCln, System.ComponentModel.ISupportInitialize).EndInit()
Me.Frame6.ResumeLayout(False)
Me.Frame5.ResumeLayout(False)
Me.ResumeLayout(False)

  End Sub
#End Region


Dim fConnect As CFrmConnect

Const FolderImgIdx = 0
Const FileImgIdx = 1


Structure FILETIME
    Dim dwLowDateTime As Long
    Dim dwHighDateTime As Long
End Structure


Dim DnldFile As String             'Name of the downloaded file and folder
Dim UpldFile, UpldFol As String    'Name of the uploaded file and folder

Dim NowList, NowCreate, NowDownload, NowUpload, NowRenameFolder, NowDeleteFolder, NowRenameFile, NowDeleteFile As Boolean

Private Declare Function MessageBox Lib "user32" Alias "MessageBoxA" (ByVal hwnd As Long, ByVal lpText As String, ByVal lpCaption As String, ByVal wType As Long) As Long


' *** General ***



Private Function SubStr(ByVal aPath As String, ByVal aFrom As Integer, ByVal aLen As Integer) As String
  If aPath = "" Then
    SubStr = ""
  Else
    SubStr = Mid(aPath, aFrom, aLen)
  End If
End Function




'Add a trailing slash
Private Function AddSlash(ByVal aPath As String) As String
  If SubStr(aPath, aPath.Length, 1) = "\" Then
    AddSlash = aPath
  Else
    AddSlash = aPath + "\"
  End If
End Function


'Remove the trailing slash
Private Function SlashOff(ByVal aPath As String) As String
  If Mid(aPath, aPath.Length, 1) = "\" Then
    SlashOff = Mid(aPath, 1, aPath.Length - 1)
  Else
    SlashOff = aPath
  End If
End Function



'Insert a leading slash
Private Function PreSlash(ByVal aPath As String) As String
  If Mid(aPath, 1, 1) = "\" Then
    PreSlash = aPath
  Else
    PreSlash = "\" + aPath
  End If
End Function



Private Sub ShowMessage(ByVal aText As String, ByVal aCaption As String)
  Call MessageBox(0&, aText, aCaption, &H1000&)
End Sub


Private Function DirExists(ByRef aDir As String) As Boolean
Dim sResult As String
On Error Resume Next
sResult = Dir(aDir, vbDirectory)
On Error GoTo 0
DirExists = sResult <> ""
End Function


Private Function ExtractFileName(ByVal vStrFullPath As String) As String
    Dim intPos As Long
    intPos = InStrRev(vStrFullPath, "\")
    ExtractFileName = Mid$(vStrFullPath, intPos + 1)
End Function


Private Function ExtractFilePath(ByVal vStrFullPath As String) As String
    Dim intPos As Long
    intPos = InStrRev(vStrFullPath, "\")
    ExtractFilePath = Mid$(vStrFullPath, 1, intPos)
End Function



Private Function GetUsername() As String
  GetUsername = FileCln.Username
  If GetUsername > "" Then Exit Function
  GetUsername = "Guest"
End Function


' Convert the FILETIME structure into a Date.
Private Function FileTimeToDate(ByVal ft As FILETIME) As Date
' FILETIME units are 100s of nanoseconds.
Const TICKS_PER_SECOND = 10000000

Dim lo_time As Double
Dim hi_time As Double
Dim seconds As Double
Dim hours As Double
Dim the_date As Date

    ' Get the low order data.
    If ft.dwLowDateTime < 0 Then
        lo_time = 2 ^ 31 + (ft.dwLowDateTime And &H7FFFFFFF)
    Else
        lo_time = ft.dwLowDateTime
    End If

    ' Get the high order data.
    If ft.dwHighDateTime < 0 Then
        hi_time = 2 ^ 31 + (ft.dwHighDateTime And _
            &H7FFFFFFF)
    Else
        hi_time = ft.dwHighDateTime
    End If

    ' Combine them and turn the result into hours.
    seconds = (lo_time + 2 ^ 32 * hi_time) / _
        TICKS_PER_SECOND
    hours = CLng(seconds / 3600)
    seconds = seconds - hours * 3600

    ' Make the date.
    the_date = DateAdd("h", hours - 4, "1/1/1601 0:00:00 AM")
    the_date = DateAdd("s", seconds, the_date)
    FileTimeToDate = the_date
End Function




' *** Working ***


'Provide an error desctiption
Private Function ErrorText(ByVal aCode As Long) As String
  ErrorText = ""
  If aCode = 0 Then Exit Function
  Select Case aCode
    Case 100
      ErrorText = "Wrong CRC"
    Case 101
      ErrorText = "Broken connection"
    Case 200
      ErrorText = "User break (client)"
    Case 201
      ErrorText = "Invalid handle (client)"
    Case 202
      ErrorText = "Client is not signed in"
    Case 203
      ErrorText = "There is no assigned event handler (client)"
    Case 204
      ErrorText = "There is an error in the event handler (client)"
    Case 205
      ErrorText = "Operation is already in progress (client)"
    Case 206
      ErrorText = "Cannot get file information (client)"
    Case 207
      ErrorText = "Cannot create folder (client)"
    Case 208
      ErrorText = "Cannot delete folder (client)"
    Case 209
      ErrorText = "Cannot delete file (client)"
    Case 210
      ErrorText = "Cannot rename folder (client)"
    Case 211
      ErrorText = "Cannot rename file (client)"
    Case 212
      ErrorText = "Cannot open file (client)"
    Case 213
      ErrorText = "Cannot create file (client)"
    Case 214
      ErrorText = "Cannot read from file (client)"
    Case 215
      ErrorText = "Cannot write to file (client)"
    Case 216
      ErrorText = "Cannot rename temporary file (client)"
    Case 301
      ErrorText = "Cannot start server"
    Case 302
      ErrorText = "Access denied"
    Case 303
      ErrorText = "User break (server)"
    Case 304
      ErrorText = "Invalid handle (server)"
    Case 305
      ErrorText = "There is no assigned event handler (server)"
    Case 306
      ErrorText = "There is an error in the event handler (server)"
    Case 307
      ErrorText = "Operation is already in progress (server)"
    Case 308
      ErrorText = "Cannot get file information (server)"
    Case 309
      ErrorText = "Cannot create folder (server)"
    Case 310
      ErrorText = "Cannot delete folder (server)"
    Case 311
      ErrorText = "Cannot delete file (server)"
    Case 312
      ErrorText = "Cannot rename folder (server)"
    Case 313
      ErrorText = "Cannot rename file (server)"
    Case 314
      ErrorText = "Cannot open file (server)"
    Case 315
      ErrorText = "Cannot create file (server)"
    Case 316
      ErrorText = "Cannot read from file (server)"
    Case 317
      ErrorText = "Cannot write to file (server)"
    Case 318
      ErrorText = "Cannot rename temporary file (server)"
  Case Else
    ErrorText = "Unknown error"
  End Select

End Function




'Display an error message, if there is
Private Sub CheckError(ByVal aCode As Long)
  If aCode = 0 Then Exit Sub
  Call ShowMessage(ErrorText(aCode), "Error")
End Sub





  'Initializations
  Private Sub fMain_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load
    fConnect = New CFrmConnect   'create connection form
    UpdateStatus()
  End Sub





  'Update the buttons state and the status text
  Private Sub UpdateStatus()

  If FileCln.Connected Then
    'already connected
    btnConnect.Enabled = False
    btnCancel.Enabled = False
    btnDisconnect.Enabled = True
    StatusBar.Panels.Item(0).Text = " Connected"
    StatusBar.Panels.Item(1).Text = FileCln.ServerAddress + ":" + Str(FileCln.ServerPort)
    If FileCln.Signedin Then
      StatusBar.Panels.Item(1).Text = " User: " + GetUsername()
    Else
      StatusBar.Panels.Item(1).Text = " Not signed in"
    End If
  Else
    StatusBar.Panels.Item(1).Text = ""
    If FileCln.Connecting Then
      'now connecting
      btnConnect.Enabled = False
      btnCancel.Enabled = True
      btnDisconnect.Enabled = False
      StatusBar.Panels.Item(0).Text = "Connecting"
    Else
      'not connected
      btnConnect.Enabled = True
      btnCancel.Enabled = False
      btnDisconnect.Enabled = False
      StatusBar.Panels.Item(0).Text = "Disconnected"
    End If
  End If

  Call UpdateButtons()
  End Sub



'Update the buttons state
Private Sub UpdateButtons()
  btnList.Enabled = False
  btnIn.Enabled = False
  btnUp.Enabled = False
  btnNew.Enabled = False
  btnDownload.Enabled = False
  btnUpload.Enabled = False
  btnRename.Enabled = False
  btnDelete.Enabled = False
  btnAbortDnld.Enabled = NowDownload
  btnAbortUpld.Enabled = NowUpload

  If Not lvFiles.Enabled Then Exit Sub

  btnUp.Enabled = txtFolder.Text > "\"
  btnNew.Enabled = Not NowCreate
  btnList.Enabled = Not NowList
  btnUpload.Enabled = Not NowUpload

  If lvFiles.SelectedItems.Count > 0 Then
    btnIn.Enabled = (lvFiles.SelectedItems(0).ImageIndex = FolderImgIdx) And Not NowList
    If lvFiles.SelectedItems(0).ImageIndex = FolderImgIdx Then
      'folder
      btnRename.Enabled = Not NowRenameFolder
      btnDelete.Enabled = Not NowDeleteFolder
    Else
      'file
      btnDownload.Enabled = Not NowDownload
      btnRename.Enabled = Not NowRenameFile
      btnDelete.Enabled = Not NowDeleteFile
    End If
  End If
End Sub






  '*** Event handlers

Private Sub lvFiles_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles lvFiles.DoubleClick
  If lvFiles.SelectedItems.Count = 0 Then Exit Sub
  If lvFiles.SelectedItems(0).ImageIndex = FolderImgIdx Then
    If lvFiles.SelectedItems(0).Text = ".." Then
      Call GoUpFolder()
    Else
      Call GoInFolder()
    End If
  Else
    Call GoDownload()
  End If
End Sub


  Private Sub lvFiles_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lvFiles.SelectedIndexChanged
    UpdateButtons()
  End Sub


  Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
    End
  End Sub



'Initiate a connection request
Private Sub btnConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnConnect.Click
  If fConnect.ShowDialog <> DialogResult.OK Then Exit Sub

  If fConnect.txtKey.Text() > "" Then
    FileCln.SecurityMode = 2  'shared secret key
    FileCln.SecretKey = fConnect.txtKey.Text
  Else
    FileCln.SecurityMode = 0  ' no encryption
  End If
  If Not FileCln.Connect(fConnect.txtHost.Text, Val(fConnect.txtPort.Text)) Then
    MsgBox("Error Code: " + Str(FileCln.LastError))
  End If

  UpdateStatus()
End Sub



  'Cancel the connection attempt
  Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
    If Not FileCln.Connecting Then Exit Sub
    FileCln.Disconnect()
  End Sub



  'Disconnect from the server
  Private Sub btnDisconnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDisconnect.Click
    If Not FileCln.Connected Then Exit Sub
    FileCln.Disconnect()
    Call DoDisconnected()
  End Sub



  'Connection request is completed
  Private Sub FileCln_OnConnected(ByVal sender As Object, ByVal e As System.EventArgs) Handles FileCln.OnConnected
    lvFiles.Enabled = True
    txtFolder.Text = "\"
    UpdateStatus()
    Call FileCln.SignIn("", "")  'sign-in as a guest
  End Sub


  'Connection request failed
  Private Sub FileCln_OnClosed(ByVal sender As Object, ByVal e As System.EventArgs) Handles FileCln.OnClosed
    MsgBox("Cannot connect to " + fConnect.txtHost.Text + ":" + fConnect.txtPort.Text, , "Error")
    Call DoDisconnected()
    UpdateStatus()
  End Sub



  'The connection is broken
  Private Sub FileCln_OnDisconnected(ByVal sender As Object, ByVal e As System.EventArgs) Handles FileCln.OnDisconnected
    Call DoDisconnected()
  End Sub



Private Sub DoDisconnected()
  lvFiles.Enabled = False
  txtFolder.Text = ""
  lvFiles.Items.Clear()
  lvFiles.Enabled = False
  UpdateStatus()
End Sub

'The sign-in request is completed
Private Sub FileCln_OnSigninDone(ByVal sender As Object, ByVal e As AxbsFileClientSDK.IBSFileClnXEvents_OnSigninDoneEvent) Handles FileCln.OnSigninDone
  UpdateStatus()
  If FileCln.Signedin Then
    ListFolder()
  End If
End Sub




' *** listing ***

  Private Sub btnList_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnList.Click
    ListFolder()
  End Sub


'Request the folder contents
Private Sub ListFolder()
  If NowList Then Exit Sub
  If FileCln.ListFolder(txtFolder.Text) Then
    NowList = True
    lvFiles.Items.Clear()
    btnList.Enabled = False
    If txtFolder.Text > "\" Then
      Call DoHaveListItem("..", True, 0, 0, 0, 0)
    End If
  Else
    CheckError(FileCln.LastError)
  End If
End Sub



'Process a list item
Private Sub DoHaveListItem(ByVal aName As String, ByVal aFolder As Boolean, ByVal aLoSize As Long, ByVal aHiSize As Long, ByVal aLoTime As Long, ByVal aHiTime As Long)
    Dim LI As ListViewItem
    Dim ft As FILETIME
    Dim Dt As Date

    LI = lvFiles.Items.Add(aName)
    If aFolder Then
      LI.ImageIndex = FolderImgIdx
      LI.SubItems.Add(" ")
    Else
      LI.ImageIndex = FileImgIdx
      LI.SubItems.Add(Str(aLoSize))
    End If

    ft.dwHighDateTime = aHiTime
    ft.dwLowDateTime = aLoTime
    Dt = FileTimeToDate(ft)
    LI.SubItems.Add(Dt)
End Sub


'A list item is available
Private Sub FileCln_OnHaveListItem(ByVal sender As Object, ByVal e As AxbsFileClientSDK.IBSFileClnXEvents_OnHaveListItemEvent) Handles FileCln.OnHaveListItem
  Call DoHaveListItem(e.aName, e.aFolder, e.aSizeLo, e.aSizeHi, e.aTimeLo, e.aTimeHi)
End Sub



'End of the list
Private Sub FileCln_OnListFolderDone(ByVal sender As Object, ByVal e As AxbsFileClientSDK.IBSFileClnXEvents_OnListFolderDoneEvent) Handles FileCln.OnListFolderDone
  NowList = False
  'CheckError(aCode)
  UpdateButtons()
End Sub




' *** folders ***



Private Sub GoInFolder()
  If lvFiles.SelectedItems.Count = 0 Then Exit Sub
  txtFolder.Text = AddSlash(txtFolder.Text) + lvFiles.SelectedItems(0).Text
  Call ListFolder()
End Sub




Private Sub GoUpFolder()
  Dim S As String
  Dim p As Long

  S = SlashOff(txtFolder.Text)
  If S = "" Then Exit Sub 'nothing to do
  p = Len(S)
  Do While p > 0
    If Mid(S, p, 1) = "\" Then Exit Do
    p = p - 1
  Loop
  txtFolder.Text = PreSlash(Mid(S, 1, p - 1))
  Call ListFolder()
End Sub






Private Sub btnIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnIn.Click
  GoInFolder()
End Sub


Private Sub btnUp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUp.Click
  GoUpFolder()
End Sub






' *** new folder ***



'Request a new folder
Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
  Dim Nm As String
  Nm = InputBox("Folder name:", "Create folder")
  If Nm = "" Then Exit Sub
  If FileCln.CreateFolder(AddSlash(txtFolder.Text) + Nm) Then
    NowCreate = True
  Else
    CheckError(FileCln.LastError)
  End If
  UpdateButtons()
End Sub



'A new folder is created
Private Sub FileCln_OnCreateFolderDone(ByVal sender As Object, ByVal e As AxbsFileClientSDK.IBSFileClnXEvents_OnCreateFolderDoneEvent) Handles FileCln.OnCreateFolderDone
  NowCreate = False
  CheckError(e.aCode)
  UpdateButtons()
  If e.aCode > 0 Then Exit Sub
  Call ListFolder()
End Sub





' *** renaming ***


'Send rename request
Private Sub btnRename_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRename.Click
  Dim Nm As String

  If lvFiles.SelectedItems.Count = 0 Then Exit Sub
  If lvFiles.SelectedItems(0).ImageIndex = FolderImgIdx Then
    'it is a folder
    Nm = InputBox("New name:", "Rename folder")
    If Nm = "" Then Exit Sub
    If FileCln.RenameFolder(AddSlash(txtFolder.Text) + lvFiles.SelectedItems(0).Text, AddSlash(txtFolder.Text) + Nm) Then
      NowRenameFolder = True
    Else
      CheckError(FileCln.LastError)
    End If
  Else
    'it is a file
    Nm = InputBox("New name:", "Rename file")
    If Nm = "" Then Exit Sub
    If FileCln.RenameFile(AddSlash(txtFolder.Text) + lvFiles.SelectedItems(0).Text, AddSlash(txtFolder.Text) + Nm) Then
      NowRenameFile = True
    Else
      CheckError(FileCln.LastError)
    End If
  End If
  Call UpdateButtons()
End Sub






'A folder is renamed
Private Sub FileCln_OnRenameFolderDone(ByVal sender As Object, ByVal e As AxbsFileClientSDK.IBSFileClnXEvents_OnRenameFolderDoneEvent) Handles FileCln.OnRenameFolderDone
  NowRenameFolder = False
  CheckError(e.aCode)
  Call UpdateButtons()
  If e.aCode > 0 Then Exit Sub
  Call ListFolder()
End Sub



'A file is renamed
Private Sub FileCln_OnRenameFileDone(ByVal sender As Object, ByVal e As AxbsFileClientSDK.IBSFileClnXEvents_OnRenameFileDoneEvent) Handles FileCln.OnRenameFileDone
  NowRenameFile = False
  CheckError(e.aCode)
  Call UpdateButtons()
  If e.aCode > 0 Then Exit Sub
  Call ListFolder()
End Sub




' *** deletion ***


'Send delete request
Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDelete.Click
  If lvFiles.SelectedItems.Count = 0 Then Exit Sub
  If lvFiles.SelectedItems(0).ImageIndex = FolderImgIdx Then
    'it is a folder
    If FileCln.DeleteFolder(AddSlash(txtFolder.Text) + lvFiles.SelectedItems(0).Text) Then
      NowDeleteFolder = True
    Else
      CheckError(FileCln.LastError)
    End If
  Else
    'it is a file
    If FileCln.DeleteFile(AddSlash(txtFolder.Text) + lvFiles.SelectedItems(0).Text) Then
      NowDeleteFile = True
    Else
      CheckError(FileCln.LastError)
    End If
  End If
  Call UpdateButtons()
End Sub



'A folder is deleted
Private Sub FileCln_OnDeleteFolderDone(ByVal sender As Object, ByVal e As AxbsFileClientSDK.IBSFileClnXEvents_OnDeleteFolderDoneEvent) Handles FileCln.OnDeleteFolderDone
  NowDeleteFolder = False
  CheckError(e.aCode)
  Call UpdateButtons()
  If e.aCode > 0 Then Exit Sub
  Call ListFolder()
End Sub



'A file is deleted
Private Sub FileCln_OnDeleteFileDone(ByVal sender As Object, ByVal e As AxbsFileClientSDK.IBSFileClnXEvents_OnDeleteFileDoneEvent) Handles FileCln.OnDeleteFileDone
  NowDeleteFile = False
  CheckError(e.aCode)
  Call UpdateButtons()
  If e.aCode > 0 Then Exit Sub
  Call ListFolder()
End Sub






' *** Uploading ***



'Send upload request
Private Sub btnUpload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnUpload.Click
  On Error GoTo IsCanceled

  OpenDlg.FileName = ""
  If OpenDlg.ShowDialog() <> DialogResult.OK Then Exit Sub

  UpldFile = OpenDlg.FileName
  If FileCln.Upload(UpldFile, txtFolder.Text) Then
    NowUpload = True
    UpldFol = txtFolder.Text
    txtUpload.Text = ExtractFileName(UpldFile) + ": handshaking"
  Else
    CheckError(FileCln.LastError)
  End If
  UpdateStatus()

IsCanceled:
End Sub


'Abort the upload operation
Private Sub btnAbortUpld_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbortUpld.Click
  If Not FileCln.CancelUpload Then
    CheckError(FileCln.LastError)
  End If
End Sub



'The upload is completed
Private Sub FileCln_OnUploadDone(ByVal sender As Object, ByVal e As AxbsFileClientSDK.IBSFileClnXEvents_OnUploadDoneEvent) Handles FileCln.OnUploadDone
  If e.aCode = 0 Then
    txtUpload.Text = ExtractFileName(UpldFile) + " - Done."
  Else
    txtUpload.Text = ExtractFileName(UpldFile) + " - Aborted: " + ErrorText(e.aCode)
  End If
  NowUpload = False
  Call UpdateButtons()
  If UpldFol = txtFolder.Text Then
    Call ListFolder()
  End If
End Sub




'Upload progress info
Private Sub FileCln_OnUploadProgress(ByVal sender As Object, ByVal e As AxbsFileClientSDK.IBSFileClnXEvents_OnUploadProgressEvent) Handles FileCln.OnUploadProgress
  txtUpload.Text = ExtractFileName(UpldFile) + " - " + Str(e.aCountLo) + "/" + Str(e.aSizeLo)
End Sub





' *** downloading ***



'Send download request
Private Sub GoDownload()
  If lvFiles.SelectedItems.Count = 0 Then Exit Sub
  If lvFiles.SelectedItems(0).ImageIndex = FolderImgIdx Then Exit Sub

  SaveDlg.FileName = lvFiles.SelectedItems(0).Text
  If SaveDlg.ShowDialog() <> DialogResult.OK Then Exit Sub
  DnldFile = lvFiles.SelectedItems(0).Text

  If FileCln.Download(AddSlash(txtFolder.Text) + lvFiles.SelectedItems(0).Text, ExtractFilePath(SaveDlg.FileName)) Then
    NowDownload = True
    txtDownload.Text = DnldFile + ": handshaking"
  Else
    CheckError(FileCln.LastError)
  End If
  UpdateStatus()
End Sub






Private Sub btnDownload_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDownload.Click
  GoDownload()
End Sub




'Abort download operation
Private Sub btnAbortDnld_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAbortDnld.Click
  If Not FileCln.CancelDownload Then
    CheckError(FileCln.LastError)
  End If
End Sub



'The download is completed
Private Sub FileCln_OnDownloadDone(ByVal sender As Object, ByVal e As AxbsFileClientSDK.IBSFileClnXEvents_OnDownloadDoneEvent) Handles FileCln.OnDownloadDone
  If e.aCode = 0 Then
    txtDownload.Text = DnldFile + " - Done."
  Else
    txtDownload.Text = DnldFile + " - Aborted: " + ErrorText(e.aCode)
  End If
  NowDownload = False
  Call UpdateButtons()
End Sub




'Download progress info
Private Sub FileCln_OnDownloadProgress(ByVal sender As Object, ByVal e As AxbsFileClientSDK.IBSFileClnXEvents_OnDownloadProgressEvent) Handles FileCln.OnDownloadProgress
  txtDownload.Text = DnldFile + " - " + Str(e.aCountLo) + "/" + Str(e.aSizeLo)
End Sub


  Private Sub FileCln_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FileCln.Enter

  End Sub
End Class




By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
Canada Canada
A software thinker

Comments and Discussions