Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Option Explicit
- '#####################################################
- '# Script: UploadLatest.vbs @ G6FTPServer(3.2.0.72)
- '# Author: IceMan @ tbm_iceman@hotmail.com (MSN)
- '#
- '# Date: 02-09-2004
- '# Last Updated: 20-09-2004
- '#
- '# DESCRIPTION:
- '# -This script will print the names/size of files
- '# -within a set folder that were created/modified
- '# -within a certain amount of time eg. 24 hours.
- '# -It will scan all subfolders & files inside the
- '# -desired upload folder.
- '# *********************************
- '# NOTE:
- '# -Remember to add the script to domain scripts
- '# -if you want it to automaticly run the Parser
- '# -everyday.
- '# -The Parser is also run every time a user
- '# -disconnects.
- '#
- '# -The list is automaticly sent on successful
- '# -login or on the [SITE-Command] SITE LatestUpload
- '#
- '# *********************************
- '# Plz don't steal my code.
- '# If you do plz leave this message... :)
- '#####################################################
- '
- ' Path to where files are uploaded... duh? :P
- ' NB: Format must be closed with a "\"
- Const UploadPath = "H:\Upload\"
- '
- ' Path to where you want the log-file
- ' NB: Format must be closed with a "\"
- Const LogFilePath = "H:\"
- '
- ' File name of the log-file
- ' NB: Remember to include file extension
- Const LogFileName = "Upload.txt"
- '
- ' Interval type and span.
- ' If you want all files under 24 hours then set it to:
- ' IntervalType to "h"
- ' IntervalSpan to 24
- ' Or what about under one month? Set it to:
- ' IntervalType = "m"
- ' IntervalSpan = 1
- ' ------------------------
- ' Type Description
- ' ------------------------
- ' yyyy Year
- ' m Month
- ' d Day
- ' h Hour
- ' n Minute
- ' s Second
- ' ------------------------
- Const IntervalType = "h"
- Const IntervalSpan = 24
- '
- ' Convert FileSize to KB/MB/GB/TB
- '
- Const UseSizeFormat = True
- '
- ' FileName/FileSize Lenght
- ' NB: FileSizeLenght should always be 10 if UseFileSize is True
- Const FileNameLenght = 55
- Const FileSizeLenght = 10
- Sub OnClientLoggedIn()
- Call PlayFile("ClientLoggedIn")
- End Sub
- Sub OnSiteLatestUpload(param)
- Call PlayFile("Site")
- End Sub
- Sub OnClientDisconnected()
- Call Parser()
- End Sub
- 'Domain Functions
- Sub OnEveryDay()
- Call Parser()
- End Sub
- '*************************************************************************
- '**** DO NOT EDIT BELOW **** DO NOT EDIT BELOW **** DO NOT EDIT BELOW ****
- '*************************************************************************
- '**** DO NOT EDIT BELOW **** DO NOT EDIT BELOW **** DO NOT EDIT BELOW ****
- '*************************************************************************
- Dim vbCrLf : vbCrLf = Chr(13)&Chr(10)
- Dim ExeTime, FSO
- Set FSO = CreateObject("Scripting.FileSystemObject")
- '-----------------------------------------------------------------------
- ' Functions used in script
- '
- Function ParseFolder(Folder)
- Dim SubFolders, SubFolder
- ParseFile(Folder)
- Set SubFolders = Folder.SubFolders
- If SubFolders.Count > 0 Then
- For Each SubFolder In SubFolders
- ParseFolder(SubFolder)
- Next
- End If
- End Function
- Function ParseFile(Folder)
- Dim Files, File
- Set Files = Folder.Files
- If Files.Count > 0 Then
- For Each File In Files
- If DateDiff(IntervalType,File.DateLastModified,ExeTime) <= IntervalSpan OR DateDiff(IntervalType,File.DateCreated,ExeTime) <= IntervalSpan Then
- WriteUploadLog(File)
- End If
- Next
- End If
- End Function
- Function WriteUploadLog(File)
- Dim ForAppending, LogFile, Line
- ForAppending = 8
- Set FSO = CreateObject("Scripting.FileSystemObject")
- Set LogFile = FSO.OpenTextFile(LogFilePath & LogFileName, ForAppending, true)
- Line = File.Name & Chr(9) & File.Size
- LogFile.WriteLine(Line)
- LogFile.Close
- Set FSO = Nothing
- End Function
- Function CreateFile()
- Dim Create
- Set FSO = CreateObject("Scripting.FileSystemObject")
- If Not FSO.FileExists(LogFilePath & LogFileName) Then
- If Not FSO.FolderExists(LogFilePath) Then
- FSO.CreateFolder(LogFilePath)
- End If
- Set Create = FSO.CreateTextFile(LogFilePath & LogFileName, False)
- Create.Close
- End If
- End Function
- Function DeleteFile()
- Set FSO = CreateObject("Scripting.FileSystemObject")
- If FSO.FileExists(LogFilePath & LogFileName) Then
- FSO.DeleteFile(LogFilePath & LogFileName)
- End If
- End Function
- Function PlayFile(Trigger)
- Const OpenFileForReading = 1
- Const OpenFileForWriting = 2
- Const OpenFileForAppending = 8
- Dim File, FileStream, OutPut, HRulor, Msg
- Set FSO = CreateObject("Scripting.FileSystemObject")
- If FSO.FileExists(LogFilePath & LogFileName) Then
- Set File = FSO.GetFile(LogFilePath & LogFileName)
- Set FileStream = File.OpenAsTextStream(OpenFileForReading)
- HRulor = "|" & String(FileNameLenght+FileSizeLenght+2, "-") & "|"
- Msg = vbCrLf
- Msg = Msg & HRulor & vbCrLf
- Msg = Msg & "| " & FormatLine("Latest Upload to the server..." &Chr(9)) & " |" & vbCrLf
- Msg = Msg & HRulor & vbCrLf
- Msg = Msg & "| " & FormatLine("FileName" &Chr(9)& "FileSize") & " |" & vbCrLf
- Msg = Msg & HRulor & vbCrLf
- If FileStream.AtEndOfStream <> True Then
- Do Until FileStream.AtEndOfStream
- Msg = Msg & "| " & FormatLine(FileStream.ReadLine) & " |" & vbCrLf
- Loop
- Else
- Msg = Msg & "| " & FormatLine("No files within last "& IntervalSpan & IntervalType & "!" & Chr(9)) & " |" & vbCrLf
- End If
- Msg = Msg & HRulor & vbCrLf & vbCrLf
- Call SentMsg(Trigger,Msg)
- FileStream.Close
- Else
- Client.Post 501, "Script-Error: (SITE LATESTUPLOAD) File doesn't exist - " & LogFilePath & LogFileName
- End If
- End Function
- Function FormatLine(Line)
- Dim FileName, FileSize, arrTmp
- arrTmp = Split(Line,Chr(9))
- If Len(arrTmp(0)) < FileNameLenght Then
- FileName = arrTmp(0) & String(FileNameLenght-Len(arrTmp(0)), " ")
- Else
- FileName = arrTmp(0) & " "
- End If
- FileSize = FormatSize(arrTmp(1))
- If Len(FileSize) < FileSizeLenght Then
- FileSize = String(FileSizeLenght-Len(FileSize), " ") & FileSize
- End If
- FormatLine = FileName & FileSize
- End Function
- Function FormatSize(Size)
- If Not IsNumeric(Size) Then
- FormatSize = Size
- Exit Function
- End If
- If Not UseSizeFormat Then
- FormatSize = Tools.FormatSize(Size,1,False)
- Exit Function
- End If
- Size = Tools.FormatSize(Size,0,False)
- If Right(Size,2) = " B" Then Size = Size & " "
- FormatSize = Size
- End Function
- Function Parser()
- ExeTime = Now()
- Dim Folder
- Call DeleteFile()
- Call CreateFile()
- If (FSO.FolderExists(UploadPath)) Then
- Set Folder = FSO.GetFolder(UploadPath)
- ParseFolder(Folder)
- Else
- Client.Send 501, "Script-Error: UploadPath doesn't exist: " & UploadPath
- End If
- End Function
- Function SentMsg(Trigger,strOutput)
- Dim Manager, Version
- Set Manager = CreateObject("G6FTPServer.Manager")
- Version = cStr(Manager.Status.Version)
- If StrComp(Version, "v3.1.0 (Build 70)", 1) <= 0 Then
- Client.send 220, strOutput
- Else
- Select Case Trigger
- Case "Site"
- Client.send 220, strOutput
- Case "ClientLoggedIn"
- Client.Post(strOutput)
- Case Else
- Client.Send(strOutput)
- End Select
- End If
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement