Advertisement
EIKA_inc

UploadLatest.vbs

Jun 21st, 2022
1,408
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Option Explicit
  2. '#####################################################
  3. '# Script: UploadLatest.vbs @ G6FTPServer(3.2.0.72)
  4. '# Author: IceMan @ tbm_iceman@hotmail.com (MSN)
  5. '#
  6. '# Date:         02-09-2004
  7. '# Last Updated: 20-09-2004
  8. '#
  9. '# DESCRIPTION:
  10. '# -This script will print the names/size of files
  11. '# -within a set folder that were created/modified
  12. '# -within a certain amount of time eg. 24 hours.
  13. '# -It will scan all subfolders & files inside the
  14. '# -desired upload folder.
  15. '# *********************************
  16. '# NOTE:
  17. '# -Remember to add the script to domain scripts
  18. '# -if you want it to automaticly run the Parser
  19. '# -everyday.
  20. '# -The Parser is also run every time a user
  21. '# -disconnects.
  22. '#
  23. '# -The list is automaticly sent on successful
  24. '# -login or on the [SITE-Command] SITE LatestUpload
  25. '#
  26. '# *********************************
  27. '# Plz don't steal my code.
  28. '# If you do plz leave this message... :)
  29. '#####################################################
  30.  
  31. '
  32. ' Path to where files are uploaded... duh? :P
  33. ' NB: Format must be closed with a "\"
  34. Const UploadPath = "H:\Upload\"
  35.  
  36. '
  37. ' Path to where you want the log-file
  38. ' NB: Format must be closed with a "\"
  39. Const LogFilePath = "H:\"
  40.  
  41. '
  42. ' File name of the log-file
  43. ' NB: Remember to include file extension
  44. Const LogFileName = "Upload.txt"
  45.  
  46. '
  47. ' Interval type and span.
  48. ' If you want all files under 24 hours then set it to:
  49. '   IntervalType to "h"
  50. '   IntervalSpan to 24
  51. ' Or what about under one month? Set it to:
  52. '   IntervalType = "m"
  53. '   IntervalSpan = 1
  54. ' ------------------------
  55. '   Type    Description
  56. ' ------------------------
  57. '   yyyy    Year
  58. '   m       Month
  59. '   d       Day
  60. '   h       Hour
  61. '   n       Minute
  62. '   s       Second
  63. ' ------------------------
  64. Const IntervalType = "h"
  65. Const IntervalSpan = 24
  66.  
  67. '
  68. ' Convert FileSize to KB/MB/GB/TB
  69. '
  70. Const UseSizeFormat = True
  71.  
  72. '
  73. ' FileName/FileSize Lenght
  74. ' NB: FileSizeLenght should always be 10 if UseFileSize is True
  75. Const FileNameLenght = 55
  76. Const FileSizeLenght = 10
  77.  
  78.  
  79.  
  80.  
  81. Sub OnClientLoggedIn()
  82.     Call PlayFile("ClientLoggedIn")
  83. End Sub
  84.  
  85. Sub OnSiteLatestUpload(param)
  86.     Call PlayFile("Site")
  87. End Sub
  88.  
  89. Sub OnClientDisconnected()
  90.     Call Parser()
  91. End Sub
  92.  
  93. 'Domain Functions
  94. Sub OnEveryDay()
  95.     Call Parser()
  96. End Sub
  97.  
  98.  
  99. '*************************************************************************
  100. '**** DO NOT EDIT BELOW **** DO NOT EDIT BELOW **** DO NOT EDIT BELOW ****
  101. '*************************************************************************
  102. '**** DO NOT EDIT BELOW **** DO NOT EDIT BELOW **** DO NOT EDIT BELOW ****
  103. '*************************************************************************
  104.  
  105. Dim vbCrLf : vbCrLf = Chr(13)&Chr(10)
  106. Dim ExeTime, FSO
  107. Set FSO = CreateObject("Scripting.FileSystemObject")
  108.  
  109. '-----------------------------------------------------------------------
  110. ' Functions used in script
  111. '
  112. Function ParseFolder(Folder)
  113.     Dim SubFolders, SubFolder
  114.     ParseFile(Folder)
  115.     Set SubFolders = Folder.SubFolders
  116.     If SubFolders.Count > 0 Then
  117.         For Each SubFolder In SubFolders
  118.             ParseFolder(SubFolder)
  119.         Next
  120.     End If
  121. End Function
  122.  
  123. Function ParseFile(Folder)
  124.     Dim Files, File
  125.     Set Files = Folder.Files
  126.     If Files.Count > 0 Then
  127.         For Each File In Files
  128.             If DateDiff(IntervalType,File.DateLastModified,ExeTime) <= IntervalSpan OR DateDiff(IntervalType,File.DateCreated,ExeTime) <= IntervalSpan Then
  129.                 WriteUploadLog(File)
  130.             End If
  131.         Next
  132.     End If
  133. End Function
  134.  
  135. Function WriteUploadLog(File)
  136.     Dim ForAppending, LogFile, Line
  137.     ForAppending = 8
  138.  
  139.     Set FSO = CreateObject("Scripting.FileSystemObject")
  140.     Set LogFile = FSO.OpenTextFile(LogFilePath & LogFileName, ForAppending, true)
  141.  
  142.     Line = File.Name & Chr(9) & File.Size
  143.  
  144.     LogFile.WriteLine(Line)
  145.     LogFile.Close
  146.     Set FSO = Nothing
  147. End Function
  148.  
  149. Function CreateFile()
  150.     Dim Create
  151.     Set FSO = CreateObject("Scripting.FileSystemObject")
  152.     If Not FSO.FileExists(LogFilePath & LogFileName) Then
  153.         If Not FSO.FolderExists(LogFilePath) Then
  154.             FSO.CreateFolder(LogFilePath)
  155.         End If
  156.         Set Create = FSO.CreateTextFile(LogFilePath & LogFileName, False)
  157.         Create.Close
  158.     End If
  159. End Function
  160.  
  161. Function DeleteFile()
  162.     Set FSO = CreateObject("Scripting.FileSystemObject")
  163.     If FSO.FileExists(LogFilePath & LogFileName) Then
  164.         FSO.DeleteFile(LogFilePath & LogFileName)
  165.     End If
  166. End Function
  167.  
  168. Function PlayFile(Trigger)
  169.     Const OpenFileForReading = 1
  170.     Const OpenFileForWriting = 2
  171.     Const OpenFileForAppending = 8
  172.     Dim File, FileStream, OutPut, HRulor, Msg
  173.     Set FSO = CreateObject("Scripting.FileSystemObject")
  174.  
  175.     If FSO.FileExists(LogFilePath & LogFileName) Then
  176.         Set File = FSO.GetFile(LogFilePath & LogFileName)
  177.         Set FileStream = File.OpenAsTextStream(OpenFileForReading)
  178.  
  179.         HRulor = "|" & String(FileNameLenght+FileSizeLenght+2, "-") & "|"
  180.  
  181.         Msg = vbCrLf
  182.         Msg = Msg & HRulor & vbCrLf
  183.         Msg = Msg & "| " & FormatLine("Latest Upload to the server..." &Chr(9)) & " |" & vbCrLf
  184.         Msg = Msg & HRulor & vbCrLf
  185.         Msg = Msg & "| " & FormatLine("FileName" &Chr(9)& "FileSize") & " |" & vbCrLf
  186.         Msg = Msg & HRulor & vbCrLf
  187.         If FileStream.AtEndOfStream <> True Then
  188.             Do Until FileStream.AtEndOfStream
  189.                 Msg = Msg & "| " & FormatLine(FileStream.ReadLine) & " |" & vbCrLf
  190.             Loop
  191.         Else
  192.             Msg = Msg & "| " & FormatLine("No files within last "& IntervalSpan & IntervalType & "!" & Chr(9)) & " |" & vbCrLf
  193.         End If
  194.         Msg = Msg & HRulor & vbCrLf & vbCrLf
  195.        
  196.         Call SentMsg(Trigger,Msg)
  197.        
  198.         FileStream.Close
  199.     Else
  200.         Client.Post 501, "Script-Error: (SITE LATESTUPLOAD) File doesn't exist - " & LogFilePath & LogFileName
  201.     End If
  202. End Function
  203.  
  204. Function FormatLine(Line)
  205.     Dim FileName, FileSize, arrTmp
  206.     arrTmp = Split(Line,Chr(9))
  207.  
  208.     If Len(arrTmp(0)) < FileNameLenght Then
  209.         FileName = arrTmp(0) & String(FileNameLenght-Len(arrTmp(0)), " ")
  210.     Else
  211.         FileName = arrTmp(0) & " "
  212.     End If
  213.  
  214.     FileSize = FormatSize(arrTmp(1))
  215.    
  216.     If Len(FileSize) < FileSizeLenght Then
  217.         FileSize = String(FileSizeLenght-Len(FileSize), " ") & FileSize
  218.     End If
  219.  
  220.     FormatLine  = FileName & FileSize
  221. End Function
  222.  
  223. Function FormatSize(Size)
  224.     If Not IsNumeric(Size) Then
  225.         FormatSize = Size
  226.         Exit Function
  227.     End If
  228.     If Not UseSizeFormat Then
  229.         FormatSize = Tools.FormatSize(Size,1,False)
  230.         Exit Function
  231.     End If
  232.  
  233.     Size = Tools.FormatSize(Size,0,False)
  234.     If Right(Size,2) = " B" Then Size = Size & " "
  235.  
  236.     FormatSize = Size
  237. End Function
  238.  
  239. Function Parser()
  240.     ExeTime = Now()
  241.     Dim Folder
  242.  
  243.     Call DeleteFile()
  244.     Call CreateFile()
  245.  
  246.     If (FSO.FolderExists(UploadPath)) Then
  247.         Set Folder = FSO.GetFolder(UploadPath)
  248.         ParseFolder(Folder)
  249.     Else
  250.         Client.Send 501, "Script-Error: UploadPath doesn't exist: " & UploadPath
  251.     End If
  252. End Function
  253.  
  254. Function SentMsg(Trigger,strOutput)
  255.     Dim Manager, Version
  256.     Set Manager = CreateObject("G6FTPServer.Manager")
  257.  
  258.     Version = cStr(Manager.Status.Version)
  259.  
  260.     If StrComp(Version, "v3.1.0  (Build 70)", 1) <= 0 Then
  261.         Client.send 220, strOutput
  262.     Else
  263.         Select Case Trigger
  264.             Case "Site"
  265.                 Client.send 220, strOutput
  266.             Case "ClientLoggedIn"
  267.                 Client.Post(strOutput)
  268.             Case Else
  269.                 Client.Send(strOutput)
  270.         End Select
  271.     End If
  272. End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement