home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 April / ChipCD_498.iso / software / ftp / quickftp / quickftp.bas < prev    next >
BASIC Source File  |  1996-01-30  |  9KB  |  351 lines

  1. 'QUICKFTP
  2.  
  3. ' bob hanson hansonr@stolaf.edu
  4. '
  5. ' modified 1/5/96
  6. ' to incorporate SocketWrench/VB control
  7. ' from Catalyst Software (www.earthlink.com)
  8.  
  9.  
  10. 'contains all global variables for the application
  11. 'and some routines
  12. '
  13. Global Const MB_YESNO = 4
  14. Global Const MB_OKCANCEL = 1
  15. Global Const MB_ICONQUESTION = 32
  16. Global Const MB_DEFBUTTON2 = 256
  17. Global Const ID_YES = 6
  18. Global Const ID_OK = 1
  19. Global Const ID_NO = 7
  20.  
  21. Global Const LogFileName = "QUICKFTP.LOG"
  22. Global Dir_file As String, Temp_File As String
  23.  
  24. '
  25. Global doitmode ' true for cycling login/FTP/logout
  26. Global putmode  ' true for put file
  27. Global cyclemode ' true if cycling
  28.  
  29. Global HostName As String
  30. Global userid As String
  31. Global Password As String
  32.  
  33. '
  34. Global Connected As Integer   'flag to indicate connection
  35. Global OkDialog As Integer    'return variable from other forms
  36. Global inputformdata As String'return from input form
  37. Global Success As Integer     'return variable from Ftp functions
  38. Global Transtype As Integer   'should be Asc("A") or Asc("I")
  39. Global DirType As Integer     'True = long; False = short
  40. Global MaskType As String     'default = *.*  NOT IMPLEMENTED
  41. Global Src_name As String      'source file name
  42. Global Dest_name As String     'destination file name
  43. Global List_Data As String     'when coming from command line option '<filename'
  44. Global Host_File_Name As String
  45. Global Local_File_Name As String
  46. Global ServerDirect As String 'initial directory
  47. Global transferaborted As Integer
  48. Global notify As Integer
  49. Global commandmode As Integer
  50. Global clickindex As Integer
  51. Global olddirclick As Integer 'for list clicking-single only
  52. Global initialcycle As Integer
  53. Declare Function GetTempFileName Lib "Kernel" (ByVal cDriveLetter As Integer, ByVal lpPrefixString As String, ByVal wUnique As Integer, ByVal lpTempFileName As String) As Integer
  54. '__
  55. '__ GLOBAL GetTempFileName
  56. '__
  57. '__   parameter ByVal cDriveLetter As Integer
  58. '__   parameter ByVal lpPrefixString As String
  59. '__   parameter ByVal wUnique As Integer
  60. '__   parameter ByVal lpTempFileName As String
  61. '__   called by FTP_form Form_Load
  62. '__
  63.  
  64.  
  65. Declare Function GetPrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Integer, ByVal lpFilename As String) As Integer
  66. '__
  67. '__ GLOBAL GetPrivateProfileString
  68. '__
  69. '__   parameter ByVal lpApplicationName As String
  70. '__   parameter ByVal lpKeyName As Any
  71. '__   parameter ByVal lpDefault As String
  72. '__   parameter ByVal lpReturnedString As String
  73. '__   parameter ByVal nSize As Integer
  74. '__   parameter ByVal lpFilename As String
  75. '__   called by Connectform PrivateStrings
  76. '__
  77.  
  78.  
  79. Declare Function writePrivateProfileString Lib "Kernel" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lplFileName As String) As Integer
  80. '__
  81. '__ GLOBAL writePrivateProfileString
  82. '__
  83. '__   parameter ByVal lpApplicationName As String
  84. '__   parameter ByVal lpKeyName As Any
  85. '__   parameter ByVal lpString As Any
  86. '__   parameter ByVal lplFileName As String
  87. '__   called by Connectform PrivateStrings
  88. '__
  89.  
  90.  
  91. Function DirOf (fname)
  92. '__
  93. '__ GLOBAL DirOf
  94. '__
  95. '__   parameter fname
  96. '__
  97. f$ = fname
  98. DirOf = app.Path & "\"
  99. pt = 0
  100. For i = Len(f$) To 1 Step -1
  101.   If Mid(f$, i, 1) = "\" Or Mid(f$, i, 1) = ":" Then pt = i: Exit For
  102. Next i
  103. If pt > 0 Then DirOf = Left(fname, pt)
  104. End Function
  105.  
  106.  
  107. Function Get_mask_type () As String
  108. '__
  109. '__ GLOBAL Get_mask_type
  110. '__   called by FTP_form Menu_setting_items_Click
  111. '__
  112.   '
  113.   Dim Answer$, DefVal, Msg, title
  114.   '
  115.   DefVal = MaskType
  116.   Msg = "Enter file mask : "
  117.   title = "File mask"
  118.   '
  119.   Answer = InputBox$(Msg, title, DefVal)
  120.   '
  121.   Get_mask_type = Answer
  122.   '
  123. End Function
  124.  
  125.  
  126. Function getinput (prompt As String, default As String)
  127. '__
  128. '__ GLOBAL getinput
  129. '__
  130. '__   parameter prompt As String
  131. '__   parameter default As String
  132. '__   called by Connectform Check_info
  133. '__   called by GLOBAL getword
  134. '__   called by FTP_form Menu_directory_item_Click
  135. '__
  136. inputform.Caption = prompt
  137. If UCase(userid) = "ANONYMOUS" And prompt = "Password" Then
  138.   inputform.Text1.PasswordChar = ""
  139.   inputform.Text1.Text = "YourFullEmailAddressPlease"
  140. ElseIf default = "HIDDENVALUE" Then
  141.   inputform.Text1.PasswordChar = "*"
  142.   inputform.Text1.Text = ""
  143. Else
  144.   inputform.Text1.PasswordChar = ""
  145.   inputform.Text1.Text = default
  146. End If
  147. inputform.Show 1
  148. getinput = Trim(inputformdata)
  149. End Function
  150.  
  151.  
  152. Function getword (s, prompt As String, default As String)
  153. '__
  154. '__ GLOBAL getword
  155. '__
  156. '__   parameter s
  157. '__   parameter prompt As String
  158. '__   parameter default As String
  159. '__   called by FTP_form DoConnFTPDisc
  160. '__   called by FTP_form Form_Load
  161. '__   calls     GLOBAL getinput
  162. '__
  163.  getword = " "
  164.  s = Trim(s) & " "
  165.  i = InStr(s, " ")
  166.  g = Trim(Left(s, i))
  167.  s = Trim(Mid(s, i))
  168.  If g = "?" Then g = getinput(prompt, default)
  169.  getword = g
  170. End Function
  171.  
  172.  
  173. Function IsDirectory (fname)
  174. '__
  175. '__ GLOBAL IsDirectory
  176. '__
  177. '__   parameter fname
  178. '__   called by GLOBAL IsValidGet
  179. '__
  180. On Error Resume Next
  181.  IsDirectory = False
  182.  If Right(fname, 1) = "\" Then IsDirectory = True: Exit Function
  183.  i = GetAttr(fname)
  184.  If i And 16 Then IsDirectory = True
  185. End Function
  186.  
  187.  
  188. Function IsFile (fname)
  189. '__
  190. '__ GLOBAL IsFile
  191. '__
  192. '__   parameter fname
  193. '__   called by GLOBAL IsValidGet
  194. '__   called by GLOBAL IsValidPut
  195. '__
  196. On Error GoTo isfilenone
  197.  IsFile = False
  198.  i = FileLen(fname)
  199.  If i > 0 Then IsFile = True
  200. ' unit = FreeFile
  201. ' Open fname For Input As unit: Close unit
  202.  Exit Function
  203. isfilenone:
  204.  IsFile = (Err <> 53 And Err <> 76)'If file and path found (could be temporary access error)
  205.  Exit Function
  206. End Function
  207.  
  208.  
  209. Function IsValidFile (fname)
  210. '__
  211. '__ GLOBAL IsValidFile
  212. '__
  213. '__   parameter fname
  214. '__   called by GLOBAL IsValidGet
  215. '__
  216. On Error GoTo isvalidfilenot
  217.  IsValidFile = True
  218.  If FileLen(fname) <> 0 Then Exit Function
  219.  unit = FreeFile
  220.  Open fname For Output As unit: Close unit
  221.  If FileLen(fname) = 0 Then Kill fname
  222.  Exit Function
  223. isvalidfilenot:
  224.  IsValidFile = (Err = 53) Or (Err <> 53 And Err <> 76)'If file and path found (could be temporary access error)
  225.  Exit Function
  226.  
  227. End Function
  228.  
  229.  
  230. Function IsValidGet (fname)
  231. '__
  232. '__ GLOBAL IsValidGet
  233. '__
  234. '__   parameter fname
  235. '__   called by Connectform Check_info
  236. '__   calls     GLOBAL IsDirectory
  237. '__   calls     GLOBAL IsFile
  238. '__   calls     GLOBAL IsValidFile
  239. '__
  240.     IsValidGet = False
  241.     If IsFile(fname) Then
  242.       Dgdef = MB_YESNO + MB_ICONQUESTION
  243.       yesno = MsgBox("Overwrite file " & fname & "?", Dgdef)
  244.       If yesno = ID_NO Then Exit Function
  245.     ElseIf Not IsValidFile(fname) Or IsDirectory(fname) Then
  246.       MsgBox "A valid local filename is required.", 64
  247.       Exit Function
  248.     End If
  249.     IsValidGet = True
  250. End Function
  251.  
  252.  
  253. Function IsValidPut (fname)
  254. '__
  255. '__ GLOBAL IsValidPut
  256. '__
  257. '__   parameter fname
  258. '__   called by Connectform Check_info
  259. '__   calls     GLOBAL IsFile
  260. '__
  261.     IsValidPut = False
  262.     If IsFile(fname) Then
  263.         IsValidPut = True
  264.         Exit Function
  265.     End If
  266.     MsgBox "Local file " & fname & " does not exist.", 64
  267. End Function
  268.  
  269.  
  270. Sub Show_the_dir_list ()
  271. '__
  272. '__ GLOBAL Show_the_dir_list
  273. '__   called by FTP_form Do_the_dirlist
  274. '__
  275.   'read the file and display the contents in the
  276.   'list box
  277.   '
  278.   Dim Lines As Integer, FileNum As Integer
  279.   Dim Txt As String, Ch As String * 1
  280.   '
  281.   FileNum = FreeFile
  282.   Lines = 0
  283.   '
  284.   On Error GoTo Err_term
  285.   Open Dir_file For Input As #FileNum
  286.   Txt = ""
  287.   Do While Not EOF(FileNum)
  288.     Ch = Input$(1, #FileNum)
  289.     If Ch <> Chr$(13) Then
  290.       Txt = Txt & Ch
  291.     Else
  292.       Lines = Lines + 1
  293.       Ftp_form!Dir_list.AddItem Txt
  294.       Txt = ""
  295.       Ch = Input$(1, #FileNum)  'read the linefeed
  296.     End If
  297.   Loop
  298.   Close #FileNum
  299.   '
  300.   If Lines = 0 Then
  301.     Txt = "No files found"
  302.     Ftp_form!Dir_list.AddItem Txt
  303.   End If
  304.   Exit Sub
  305.   '
  306. Err_term:
  307.   Ftp_form!Message.Caption = "Error in Dir list file"
  308.   Exit Sub
  309. End Sub
  310.  
  311.  
  312. Sub switch_to (t As TextBox)
  313. '__
  314. '__ GLOBAL switch_to
  315. '__
  316. '__   parameter t As TextBox
  317. '__   called by Connectform Check_info
  318. '__   called by Connectform Form_Load
  319. '__   called by Connectform NodeEdit_GotFocus
  320. '__   called by Connectform NodeEdit_KeyPress
  321. '__   called by Connectform OptDoitAll_Click
  322. '__   called by Connectform OptFTPOnly_Click
  323. '__   called by Connectform PasswordEdit_GotFocus
  324. '__   called by Connectform PasswordEdit_KeyPress
  325. '__   called by Connectform txtDirect_GotFocus
  326. '__   called by Connectform txtDirect_KeyPress
  327. '__   called by Connectform txtLocalFile_GotFocus
  328. '__   called by Connectform txtLocalFile_KeyPress
  329. '__   called by Connectform txtRemoteFile_GotFocus
  330. '__   called by Connectform txtRemoteFile_KeyPress
  331. '__   called by Connectform UserEdit_gotfocus
  332. '__   called by Connectform UserEdit_KeyPress
  333. '__   called by Get_file Form_Activate
  334. '__   called by Get_file HostFile_KeyPress
  335. '__   called by Get_file LocalFile_KeyPress
  336. '__   called by Get_file txtCycle_GotFocus
  337. '__   called by InputForm Form_Activate
  338. '__   called by FTP_form Cycle_sec_GotFocus
  339. '__
  340.   t.SelStart = 0
  341.   t.SelLength = 1000
  342.   On Error GoTo st_cant_set
  343.   If t.Visible Then t.SetFocus
  344.   On Error GoTo 0
  345.   Exit Sub
  346. st_cant_set:
  347.   Resume Next
  348. End Sub
  349.  
  350.  
  351.