home *** CD-ROM | disk | FTP | other *** search
/ Planet Source Code Jumbo …e CD Visual Basic 1 to 7 / 1_2002.ISO / Data / Zips / CODE_UPLOAD48164152000.psc / Forms / frmMain.frm (.txt) next >
Encoding:
Visual Basic Form  |  2000-04-15  |  6.0 KB  |  147 lines

  1. VERSION 5.00
  2. Begin VB.Form frmMain 
  3.    Caption         =   "FTP Engine"
  4.    ClientHeight    =   3855
  5.    ClientLeft      =   165
  6.    ClientTop       =   735
  7.    ClientWidth     =   7695
  8.    LinkTopic       =   "Form1"
  9.    ScaleHeight     =   3855
  10.    ScaleWidth      =   7695
  11.    StartUpPosition =   3  'Windows Default
  12.    Begin VB.TextBox txtSvrLog 
  13.       Height          =   3855
  14.       Left            =   0
  15.       Locked          =   -1  'True
  16.       MultiLine       =   -1  'True
  17.       ScrollBars      =   3  'Both
  18.       TabIndex        =   0
  19.       Text            =   "frmMain.frx":0000
  20.       Top             =   0
  21.       Width           =   7695
  22.    End
  23.    Begin VB.Menu mnuFile 
  24.       Caption         =   "&File"
  25.       Begin VB.Menu mnuExit 
  26.          Caption         =   "E&xit"
  27.       End
  28.    End
  29.    Begin VB.Menu mnuServer 
  30.       Caption         =   "&Server"
  31.       Begin VB.Menu mnuStartSvr 
  32.          Caption         =   "&Start Server"
  33.       End
  34.       Begin VB.Menu mnuStopSvr 
  35.          Caption         =   "S&top  Server"
  36.       End
  37.    End
  38. Attribute VB_Name = "frmMain"
  39. Attribute VB_GlobalNameSpace = False
  40. Attribute VB_Creatable = False
  41. Attribute VB_PredeclaredId = True
  42. Attribute VB_Exposed = False
  43. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  44. 'Demo program to show off my FTP engine.
  45. 'Author: Matt Thomas (mthomas@aspire.com)
  46. 'Description: I set out to create a easy to use FTP server class module
  47. 'that you could take and drop into any program to make it an FTP server.
  48. 'Another reason was that I wanted to have an Event driven FTP server,
  49. 'working with Events makes thing soooo much easier.
  50. 'This is just a start, its not nearly complete but I wanted to show
  51. 'you all what I was working on and get some feedback.
  52. 'You should be able to use the FTP server without having to understand
  53. 'much of how it works internally.
  54. 'The two files REQUIRED for the FTP server to run are
  55. 'Server.cls and frmWinsock.frm
  56. 'The rest of the files are just small parts of this demo program.
  57. 'If you find any bugs/problems in the server code please let me know.
  58. 'Sorry for the lack of comments, I will try to add more as time goes on.
  59. 'This server seems to take a lot of memory, if anyone can see ANYWAY
  60. 'to lessen the amount of memory consumed by this program please let me know.
  61. 'The program starts off using about 2MB of ram or so.
  62. 'Ive tested it with 10 clients banging away at it, with 10 clients
  63. 'the server takes about 4MB of ram.
  64. 'To test, start the server, and login to it as anonymous
  65. 'This code/program has ONLY been tested in Visual Basic 6.
  66. 'This code/program has ONLY been tested using CuteFTP as the FTP client.
  67. 'This code/program has ONLY been tested on a Windows 2000 system.
  68. '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  69. Option Explicit
  70. '''''''''''''''''''''''''''''''''''''''''''
  71. 'Server object, events and variables
  72. '''''''''''''''''''''''''''''''''''''''''''
  73. 'Declare FTPServer as the Server object
  74. 'WithEvents so it gets the events from the Server object.
  75. Public WithEvents FTPServer As Server
  76. Attribute FTPServer.VB_VarHelpID = -1
  77. '''''''''''''''''''''''''''''''''''''''''''
  78. 'Form events
  79. '''''''''''''''''''''''''''''''''''''''''''
  80. Private Sub Form_Load()
  81.     'Create new instance of the server
  82.     Set FTPServer = New Server
  83.     'When you create an instance of the Server you need to also
  84.     'set the server instance on the frmWinsock form to the instance
  85.     'that you created here so that it can work with the instance of the
  86.     'server that you created.
  87.     Set frmWinsock.FTPServer = FTPServer
  88. End Sub
  89. Public Sub Form_Resize()
  90.     On Error Resume Next
  91.     txtSvrLog.Width = (frmMain.Width - 120)
  92.     txtSvrLog.Height = (frmMain.Height - 690)
  93. End Sub
  94. Public Sub Form_UnLoad(Cancel As Integer)
  95.     'Shutdown server, close Winsock
  96.     StopServer
  97.     'Remove the FTP server object from memory
  98.     Set FTPServer = Nothing
  99.     Set frmWinsock.FTPServer = Nothing
  100.     'Remove the forms from memory
  101.     Unload frmWinsock
  102.     Unload Me
  103.     Set frmWinsock = Nothing
  104.     Set frmMain = Nothing
  105.     End
  106. End Sub
  107. Private Sub mnuStartSvr_Click()
  108.     StartServer
  109. End Sub
  110. Private Sub mnuStopSvr_Click()
  111.     StopServer
  112. End Sub
  113. '''''''''''''''''''''''''''''''''''''''''''
  114. 'FTPServer events
  115. '''''''''''''''''''''''''''''''''''''''''''
  116. Private Sub FTPServer_ServerStarted()
  117.     'Once the server has successfully started with out errors
  118.     'and is ready to accept clients, this event sub will run.
  119.     WriteToLogWindow "Server started!", True
  120. End Sub
  121. Private Sub FTPServer_ServerStopped()
  122.     'ServerStopped() event fires after all connected clients
  123.     'have been disconnected, Winsock is shutdown and other
  124.     'misc. variables are reset.
  125.     WriteToLogWindow "Server stopped!", True
  126. End Sub
  127. Private Sub FTPServer_ServerErrorOccurred(ByVal errNumber As Long)
  128.     'Event fires when an error in the server occurs.
  129.     MsgBox FTPServer.ServerGetErrorDescription(errNumber), vbInformation, "Error occured!"
  130. End Sub
  131. Private Sub FTPServer_NewClient(ByVal ClientID As Long)
  132.     'Event fires when a new client successfully connects.
  133.     WriteToLogWindow "Client " & ClientID & " connected! (" & FTPServer.GetClientIPAddress(ClientID) & ")", True
  134. End Sub
  135. Private Sub FTPServer_ClientSentCommand(ByVal ClientID As Long, Command As String, Args As String)
  136.     'Event fires when a connected client sends a FTP command to the server.
  137.     WriteToLogWindow "Client " & ClientID & " sent: " & Command & " " & Args, True
  138. End Sub
  139. Private Sub FTPServer_ClientStatusChanged(ByVal ClientID As Long)
  140.     'Event fires when the clients status has been changed.
  141.     WriteToLogWindow "Client " & ClientID & " Status: " & FTPServer.GetClientStatus(ClientID), True
  142. End Sub
  143. Private Sub FTPServer_ClientLoggedOut(ByVal ClientID As Long)
  144.     'Event fires when a connected client disconnects/is disconnected.
  145.     WriteToLogWindow "Client " & ClientID & " logged out!", True
  146. End Sub
  147.