Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

xanburzum

[Resolvido] Verifique Se Há Novos Arquivos ou Atualizados

Recommended Posts

lista todas as pastas e arquivos quando carregado primeiro. A hora é guardada em um cookie. Então, da próxima vez que você navegue para o script, ele verifica a data-último-de cada arquivo modificado contra o registro de hora e faz um link para o download de todos os arquivos novos ou alterados. O script mostra algo como:

 

modifiedfiles.asp

 

<%@ LANGUAGE="VBScript" %>
<%Response.Buffer = False%> 
<% 


Server.ScriptTimeout = 3600
if NOT Session("fileAdmin") = "login" then
response.redirect "ulogin.asp"
end if
strOldDate = dateadd("d",-1,now())
saveDate = DateDiff("s", "01/01/1970 00:00:00", Now())
if NOT request.cookies("SaveDate")="" then
oldVisit = request.Cookies("SaveDate")
end if
response.cookies("SaveDate") = saveDate
response.Cookies("SaveDate").Expires= Date() + 365
on error resume next
%>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Arquivos</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
</head>
<body>
<h3>Verifique se há novos ou arquivos atualizados </h3>
<p>Sua primeira visita define o cookie. Na próxima visita, os arquivos que são novos ou modificados devem ser listados com download Links.</p>
<%response.write "Anterior visita timestamp: " & oldVisit & " Current visit 
timestamp: " & request.cookies("SaveDate") %>
<br>
<% 
Whichfolder=server.mappath("\") &"/" 
Dim fs, f, f1, fc 
Set fs = CreateObject("Scripting.FileSystemObject") 
Set f = fs.GetFolder(Whichfolder) 
Set fc = f.subfolders 
Set fa = f.files
For Each f1 in fa 
rootDate = f1.DateLastModified
Xdate = DateDiff("s", "01/01/1970 00:00:00", rootDate)
curDate = DateDiff("s", "01/01/1970 00:00:00", Now()) 
if Clng(Xdate) > Clng(oldVisit) then
response.write "<b>Este arquivo foi modificado ou é novos:</b>"
response.write "<BR>Arquivo mod: " & Xdate & " | Hora Atual: " & curDate & " | Prev. Visit: " & oldVisit &"<BR>"
Response.write ("<b><a target=_blank href=download.asp?file=" & Whichfolder & f1.name &">" & f1.name & "</a></b>" & " ultima Modificação: " & 
f1.DateLastModified&"<BR>") 
end if
Next 
For Each f1 in fc 
'Response.write (f1.name & "<BR>")
response.write "<ul>"
ListFolderContents(Server.MapPath("/" & f1.name)) 
response.write "</ul>"
Next 
%>
</body>
</html>
<% sub ListFolderContents(path)
dim fs, folder, file, item, url
set fs = CreateObject("Scripting.FileSystemObject")
set folder = fs.GetFolder(path)
'Mostrar a pasta destino e info.
Response.Write("<li><b>" & folder.Name & "</b> - " _
& folder.Files.Count & " files, ")
if folder.SubFolders.Count > 0 then
Response.Write(folder.SubFolders.Count & " diretorios, ")
end if
Response.Write(Round(folder.Size / 1024) & " KB total." _
& vbCrLf)
Response.Write("<ul>" & vbCrLf)
'Apresentar uma lista de sub-pastas.
for each item in folder.SubFolders
ListFolderContents(item.Path)
next
'Apresentar uma lista de arquivos.
for each item in folder.Files
url = MapURL(item.path)
myDate = item.DateLastModified
Udate = DateDiff("s", "01/01/1970 00:00:00", myDate)
tuDate = DateDiff("s", "01/01/1970 00:00:00", Now()) 
if Clng(Udate) > Clng(oldVisit) then
response.write "<br><b>Este arquivo foi modificado ou se novos:</b>"
response.write "<BR>Arquivo mod: " & Udate & " | Hora Atual: " & tuDate & "<BR>"
Response.Write("<li><b><a href=""" & url & """>" & item.Name &"</a></B>" & " 
| <a target="&"_blank " &"href=" &"download.asp?file=" & item.path &">" & 
"Download" & "</a>" &" - " _
& item.Size & " bytes, " _
& "last modified on " & item.DateLastModified & "." _
& "</li>" & vbCrLf)
end if
next
Response.Write("</ul>" & vbCrLf)
Response.Write("</li>" & vbCrLf)
end sub
function MapURL(path)
dim rootPath, url
'Converter um arquivo físico caminho para uma URL de ligações hipertexto.
rootPath = Server.MapPath("/")
url = Right(path, Len(path) - Len(rootPath))
MapURL = Replace(url, "\", "/")
end function 
%>

download.asp

 

<% 

'este código utiliza o servidor componente ASPupload - veja ASPupload.com ou usar outro script para forçar download

if NOT Session("fileAdmin") = "login" then
response.redirect "ulogin.asp"
end if


'Whichfolder=server.mappath("\") &"/"
sFile = request.querystring("file")

Set Upload = Server.CreateObject("Persits.Upload")

' Construir caminho do arquivo
Path = sFile

Upload.SendBinary Path, True, "application/octet-binary", True
%>

 

 

<%
'Alterar senha na linha 14 para a sua própria
' ****** check login ********
public function loginTestUser (ByRef userMessage, ByRef objRequest)
Dim retValue

retValue = false
userMessage = "<b>Digite o usuário teste para senha abaixo.</b>"

if objRequest("logout") = "yes" then
Session("fileAdmin") = ""
userMessage = "<b>Você saiu com êxito.<b>"

elseif objRequest("pwd") = "PassWord" then 'Mudar a senha
Session("fileAdmin") = "login"
userMessage = "<b>você esta logado com sucesso.</b>"
retValue = true

elseif not IsNull(objRequest("pwd")) then
Session("fileAdmin") = ""
userMessage = "<b>Senha incorreta, por favor, tente novamente.</b>"

end if

loginTestUser = retValue
end function
%>
<%


Dim userMessage

loginTestUser userMessage, request
%>




<p><b>Login</b></p>

<p><%=userMessage%></p>

<%if Session("fileAdmin") = "login" then%>
<p>você esta logado.</p>

<p>Vá para o <a href="modifiedfiles.asp">Files Page</a></p>

<form method=post action="ulogin.asp">
<input type=hidden name=logout value=yes ID="Hidden2">
<p><input type=submit value="Logout" ID="Submit2" NAME="Submit1"></p>
</form>

<%else%>
<form method=post action="ulogin.asp" ID="Form1">
<p><b>Password:</b> <input type=text name=pwd ID="Text1">     <input type=submit value="Login" ID="Submit1" NAME="Submit1"></p>
</form>

<%end if%>

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.