AutoHotkey Community

It is currently May 27th, 2012, 4:38 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: FileGetSize and ftp
PostPosted: March 6th, 2010, 9:41 pm 
Offline

Joined: December 29th, 2009, 10:58 pm
Posts: 86
Location: France
Hi!

I'have :

Code:
FileGetSize, b100,ftp://tlams.free.fr/Metin2/maj/metin2.exe
FileGetSize, b100X,C:\Users\Thomas\Desktop\metin2.exe

if b100 = b100X

{
msgbox Maj inutile
}
else
UrlDownloadToFile, http://tlams.free.fr/Metin2/maj/metin2.exe, C:\Users\Thomas\Desktop\metin2.exe


But FileGetSize does not detect the size for a file in an ftp .
How can I do?

Thx


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 6th, 2010, 10:07 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
Perhaps you could use http://www.autohotkey.com/forum/topic10510.html HTTP_QUERY_CONTENT_LENGTH to get the size :?:

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 6th, 2010, 10:44 pm 
Offline

Joined: December 29th, 2009, 10:58 pm
Posts: 86
Location: France
It's very hard !
I do not understand xD

Code:
/* ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; HttpQueryInfo ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
QueryInfoFlag:

HTTP_QUERY_RAW_HEADERS = 21
Receives all the headers returned by the server.
Each header is terminated by "\0". An additional "\0" terminates the list of headers.

HTTP_QUERY_CONTENT_LENGTH = 5
Retrieves the size of the resource, in bytes.

HTTP_QUERY_CONTENT_TYPE = 1
Receives the content type of the resource (such as text/html).

Find more at: http://msdn.microsoft.com/library/en-us/wininet/wininet/query_info_flags.asp

Proxy Settings:

INTERNET_OPEN_TYPE_PRECONFIG                    0   // use registry configuration
INTERNET_OPEN_TYPE_DIRECT                       1   // direct to net
INTERNET_OPEN_TYPE_PROXY                        3   // via named proxy
INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY  4   // prevent using java/script/INS

*/ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

HttpQueryInfo(URL, QueryInfoFlag=21, Proxy="", ProxyBypass="") {
hModule := DllCall("LoadLibrary", "str", "wininet.dll")

If (Proxy != "")
AccessType=3
Else
AccessType=1

io_hInternet := DllCall("wininet\InternetOpenA"
, "str", "" ;lpszAgent
, "uint", AccessType
, "str", Proxy
, "str", ProxyBypass
, "uint", 0) ;dwFlags
If (ErrorLevel != 0 or io_hInternet = 0) {
DllCall("FreeLibrary", "uint", hModule)
return, -1
}

iou_hInternet := DllCall("wininet\InternetOpenUrlA"
, "uint", io_hInternet
, "ftp://tlams.free.fr/Metin2/maj/metin2.exe", url
, "str", "" ;lpszHeaders
, "uint", 0 ;dwHeadersLength
, "uint", 0x80000000 ;dwFlags: INTERNET_FLAG_RELOAD = 0x80000000 // retrieve the original item
, "uint", 0) ;dwContext
If (ErrorLevel != 0 or iou_hInternet = 0) {
DllCall("FreeLibrary", "uint", hModule)
return, -1
}

VarSetCapacity(buffer, 1024, 0)
VarSetCapacity(buffer_len, 4, 0)

Loop, 5
{
  hqi := DllCall("wininet\HttpQueryInfoA"
  , "uint", iou_hInternet
  , "uint", QueryInfoFlag ;dwInfoLevel
  , "uint", &buffer
  , "uint", &buffer_len
  , "uint", 0) ;lpdwIndex
  If (hqi = 1) {
    hqi=success
    break
  }
}

IfNotEqual, hqi, success, SetEnv, res, timeout

If (hqi = "success") {
p := &buffer
Loop
{
  l := DllCall("lstrlen", "UInt", p)
  VarSetCapacity(tmp_var, l+1, 0)
  DllCall("lstrcpy", "Str", tmp_var, "UInt", p)
  p += l + 1
  res := res  . "`n" . tmp_var
  If (*p = 0)
  Break
}
StringTrimLeft, res, res, 1
}

DllCall("wininet\InternetCloseHandle",  "uint", iou_hInternet)
DllCall("wininet\InternetCloseHandle",  "uint", io_hInternet)
DllCall("FreeLibrary", "uint", hModule)

return, res
}


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2010, 1:58 am 
Offline

Joined: December 29th, 2009, 10:58 pm
Posts: 86
Location: France
:)

I'have find !


Code:
FileGetSize, b100,ftp://tlams.free.fr/Metin2/maj/mouse.cfg,
FileGetSize, b100X,C:\Users\Thomas\Desktop\mouse.cfg,


if b100:=b100X
{
msgbox Maj inutile
}
else
UrlDownloadToFile, http://tlams.free.fr/Metin2/maj/mouse.cfg, C:\Users\Thomas\Desktop\mouse.cfg
return



But there is a problem!
If I edit the file "mouse.cfg" and I raise, it does not detect the change ...
Why ?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2010, 8:41 am 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
if b100:=b100X is not correct, with := you assign a value to a variable so you can can't compare it. Perhaps use the expression mode like so

Code:
if (b100 = b100X)

_________________
AHK FAQ
TF : Text files & strings lib, TF Forum


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2010, 9:25 am 
Offline

Joined: April 19th, 2005, 10:26 am
Posts: 2249
Location: switzerland
not sure if works, must login for FTP
this example works:
Code:
   url = http://www.autohotkey.com
        ;url=ftp://tlams.free.fr/Metin2/maj/metin2.exe  ; not works
        SIZE7:=HttpQueryInfo(URL,5)
        if (size7="timeout" or size7=0 or size7=-1)
           msgbox,SIZE=%size7%`nERROR
        else
           msgbox,SIZE=%size7%
        return

/*
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; HttpQueryInfo ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
QueryInfoFlag:

HTTP_QUERY_RAW_HEADERS = 21
Receives all the headers returned by the server.
Each header is terminated by "\0". An additional "\0" terminates the list of headers.

HTTP_QUERY_CONTENT_LENGTH = 5
Retrieves the size of the resource, in bytes.

HTTP_QUERY_CONTENT_TYPE = 1
Receives the content type of the resource (such as text/html).

Find more at: http://msdn.microsoft.com/library/en-us/wininet/wininet/query_info_flags.asp

Proxy Settings:

INTERNET_OPEN_TYPE_PRECONFIG                    0   // use registry configuration
INTERNET_OPEN_TYPE_DIRECT                       1   // direct to net
INTERNET_OPEN_TYPE_PROXY                        3   // via named proxy
INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY  4   // prevent using java/script/INS


; Examples:
; url1 = http://www.autohotkey.com
; url2 = http://www.autohotkey.com/download/AutoHotkeyInstall.exe
; MsgBox % HttpQueryInfo(url1)
; MsgBox % HttpQueryInfo(url2, 5)
; MsgBox % HttpQueryInfo(url2, 1)

*/
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


HttpQueryInfo(URL, QueryInfoFlag=21, Proxy="", ProxyBypass="") {
hModule := DllCall("LoadLibrary", "str", "wininet.dll")

If (Proxy != "")
AccessType=3
Else
AccessType=1

io_hInternet := DllCall("wininet\InternetOpenA"
, "str", "" ;lpszAgent
, "uint", AccessType
, "str", Proxy
, "str", ProxyBypass
, "uint", 0) ;dwFlags
If (ErrorLevel != 0 or io_hInternet = 0) {
DllCall("FreeLibrary", "uint", hModule)
return, -1
}

iou_hInternet := DllCall("wininet\InternetOpenUrlA"
, "uint", io_hInternet
, "str", url
, "str", "" ;lpszHeaders
, "uint", 0 ;dwHeadersLength
, "uint", 0x80000000 ;dwFlags: INTERNET_FLAG_RELOAD = 0x80000000 // retrieve the original item
, "uint", 0) ;dwContext
If (ErrorLevel != 0 or iou_hInternet = 0) {
DllCall("FreeLibrary", "uint", hModule)
return, -1
}

VarSetCapacity(buffer, 1024, 0)
VarSetCapacity(buffer_len, 4, 0)

Loop, 5
{
  hqi := DllCall("wininet\HttpQueryInfoA"
  , "uint", iou_hInternet
  , "uint", QueryInfoFlag ;dwInfoLevel
  , "uint", &buffer
  , "uint", &buffer_len
  , "uint", 0) ;lpdwIndex
  If (hqi = 1) {
    hqi=success
    break
  }
}

IfNotEqual, hqi, success, SetEnv, res, timeout

If (hqi = "success") {
p := &buffer
Loop
{
  l := DllCall("lstrlen", "UInt", p)
  VarSetCapacity(tmp_var, l+1, 0)
  DllCall("lstrcpy", "Str", tmp_var, "UInt", p)
  p += l + 1
  res := res  . "`n" . tmp_var
  If (*p = 0)
  Break
}
StringTrimLeft, res, res, 1
}

DllCall("wininet\InternetCloseHandle",  "uint", iou_hInternet)
DllCall("wininet\InternetCloseHandle",  "uint", io_hInternet)
DllCall("FreeLibrary", "uint", hModule)

return, res
}
;------------------------------------------------------------------



Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2010, 11:44 am 
Offline

Joined: December 29th, 2009, 10:58 pm
Posts: 86
Location: France
Ok ! Thx you :D


Code:
FileGetSize, b100X,C:\Users\Thomas\Desktop\mouse.cfg ,

url=http://tlams.free.fr/Metin2/maj/mouse.cfg
        SIZE7:=HttpQueryInfo(URL,5)
        if (size7="timeout" or size7=0 or size7=-1)
           msgbox,SIZE=%size7%`nERROR
         
         else
            if b100X = %size7%
               {
                  msgbox Maj inutile
               }
            else
               {
               UrlDownloadToFile, http://tlams.free.fr/Metin2/maj/mouse.cfg , C:\Users\Thomas\Desktop\mouse.cfg
               }
           TrayTip, information,Fichier à jour., 3, 17
         Sleep 2000
        return

/*



:P


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: March 7th, 2010, 12:10 pm 
Offline

Joined: April 19th, 2005, 10:26 am
Posts: 2249
Location: switzerland
works for you Tlams ?
can't test it maybe I have no access
think need more brackets, specially after else ....
try this (needs httpquery, see above)

Code:
FileGetSize, b100X, %A_scriptdir%\CurrentVersion.txt
url=http://www.autohotkey.com/download/CurrentVersion.txt
        SIZE7:=HttpQueryInfo(URL,5)
        if (size7="timeout" or size7=0 or size7=-1)
           {
           msgbox,SIZE=%size7%`nERROR
           return
           }

         else
           {
            if (b100X=size7)
                  {
                  msgbox Maj inutile
                  return
                  }
            else
               {
               UrlDownloadToFile,%url% , %A_scriptdir%\CurrentVersion.txt
               TrayTip, information,Fichier à jour., 3, 17
               Sleep 2000
               }
            }
        return


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 8 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: 0x150||ISO, rbrtryn and 68 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group