Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
Visual Basic 6 - vb6 problema download da server ftp
Forum - Visual Basic 6 - vb6 problema download da server ftp

Avatar
piter123 (Normal User)
Pro


Messaggi: 145
Iscritto: 21/05/2008

Segnala al moderatore
Postato alle 10:13
Giovedė, 04/08/2011
salve, a volte e in particolar modo su un pc quando tramite vb6 lancio lo scarico di un file da un server ftp mi capita che invece di scaricarlo e sovrapporlo a quello vecchio lo prelevi dalla cache (almeno penso).

Come posso quindi prima del download da ftp cancellarlo dalla cache ?
Dico questo perchč quando mi succede, basta che cancello i file temporanei internet da explorer e il tutto mi funziona.

Grazie


Private Declare Function URLDownloadToFile Lib "urlmon" Alias _
"URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, _
ByVal szFileName As String, _
ByVal dwReserved As Long, _
ByVal lpfnCB As Long) As Long

Private Sub Command1_Click()
    NOME_FILE = "prova.txt"
    DEST_FILE = "c:\prova.txt"
    USERID = "xxxxxxxxx"
    PSW_DOWNLOAD = "xxxxxxxx"
    PORTAFTP = xxxxxxx
    IP = "xx.xxx.xxx.xx"
    URL = "FTP://" & USERID & ":" & PSW_DOWNLOAD & "@" & IP & ":" & PORTAFTP & "/" & NOME_FILE
    res = URLDownloadToFile(0, URL, DEST_FILE, 0, 0)
End Sub

PM
Avatar
wuolfit (Normal User)
Pro


Messaggi: 100
Iscritto: 19/07/2011

Up
0
Down
V
Segnala al moderatore
Postato alle 11:04
Giovedė, 04/08/2011
Beh io farei cosė.....nella form del tuo programma creerei un pulsante e immetterei nella form questo codice :

Codice sorgente - presumibilmente VB.NET

  1. Option Explicit
  2.  
  3. Private Declare Function FindFirstUrlCacheGroup Lib "wininet.dll" ( _
  4.     ByVal dwFlags As Long, _
  5.     ByVal dwFilter As Long, _
  6.     ByRef lpSearchCondition As Long, _
  7.     ByVal dwSearchCondition As Long, _
  8.     ByRef lpGroupId As Date, _
  9.     ByRef lpReserved As Long) As Long
  10.  
  11. Private Declare Function FindNextUrlCacheGroup Lib "wininet.dll" ( _
  12.     ByVal hFind As Long, _
  13.     ByRef lpGroupId As Date, _
  14.     ByRef lpReserved As Long) As Long
  15.    
  16. Private Declare Function DeleteUrlCacheGroup Lib "wininet.dll" ( _
  17.     ByVal sGroupID As Date, _
  18.     ByVal dwFlags As Long, _
  19.     ByRef lpReserved As Long) As Long
  20.    
  21. Private Declare Function FindFirstUrlCacheEntry Lib "wininet.dll" Alias "FindFirstUrlCacheEntryA" ( _
  22.     ByVal lpszUrlSearchPattern As String, _
  23.     ByRef lpFirstCacheEntryInfo As INTERNET_CACHE_ENTRY_INFO, _
  24.     ByRef lpdwFirstCacheEntryInfoBufferSize As Long) As Long
  25.    
  26. Private Type INTERNET_CACHE_ENTRY_INFO
  27.     dwStructSize As Long
  28.     szRestOfData(1024) As Long
  29. End Type
  30.  
  31. Private Declare Function DeleteUrlCacheEntry Lib "wininet.dll" Alias "DeleteUrlCacheEntryA" ( _
  32.     ByVal lpszUrlName As Long) As Long
  33.  
  34. Private Declare Function FindNextUrlCacheEntry Lib "wininet.dll" Alias "FindNextUrlCacheEntryA" ( _
  35.     ByVal hEnumHandle As Long, _
  36.     ByRef lpNextCacheEntryInfo As INTERNET_CACHE_ENTRY_INFO, _
  37.     ByRef lpdwNextCacheEntryInfoBufferSize As Long) As Long
  38.  
  39. Private Const CACHGROUP_SEARCH_ALL = &H0
  40. Private Const ERROR_NO_MORE_FILES = 18
  41. Private Const ERROR_NO_MORE_ITEMS = 259
  42. Private Const CACHEGROUP_FLAG_FLUSHURL_ONDELETE = &H2
  43. Private Const BUFFERSIZE = 2048
  44.  
  45. Private Sub Command1_Click()
  46.     Dim sGroupID As Date
  47.     Dim hGroup As Long
  48.     Dim hFile As Long
  49.     Dim sEntryInfo As INTERNET_CACHE_ENTRY_INFO
  50.     Dim iSize As Long
  51.        
  52.     On Error Resume Next
  53.    
  54.     ' Delete the groups
  55.     hGroup = FindFirstUrlCacheGroup(0, 0, 0, 0, sGroupID, 0)
  56.    
  57.     ' To avoid error using it with IE4 as FindFirstUrlCacheGroup is not implemented
  58.     If Err.Number <> 453 Then
  59.         If (hGroup = 0) And (Err.LastDllError <> 2) Then
  60.             MsgBox "An error occurred enumerating the cache groups" & Err.LastDllError
  61.             Exit Sub
  62.         End If
  63.     Else
  64.         Err.Clear
  65.     End If
  66.    
  67.     If (hGroup <> 0) Then
  68.         'we succeeded in finding the first cache group.. enumerate and
  69.         'delete
  70.         Do
  71.             If (0 = DeleteUrlCacheGroup(sGroupID, CACHEGROUP_FLAG_FLUSHURL_ONDELETE, 0)) Then
  72.                
  73.                ' To avoid error using it with IE4 as FindFirstUrlCacheGroup is not implemented
  74.                If Err.Number <> 453 Then
  75.                  MsgBox "Error deleting cache group " & Err.LastDllError
  76.                  Exit Sub
  77.                Else
  78.                   Err.Clear
  79.                End If
  80.             End If
  81.             iSize = BUFFERSIZE
  82.             If (0 = FindNextUrlCacheGroup(hGroup, sGroupID, iSize)) And (Err.LastDllError <> 2) Then
  83.                 MsgBox "Error finding next url cache group! - " & Err.LastDllError
  84.             End If
  85.         Loop Until Err.LastDllError = 2
  86.     End If
  87.  
  88.   ' Delete the files
  89.     sEntryInfo.dwStructSize = 80
  90.     iSize = BUFFERSIZE
  91.     hFile = FindFirstUrlCacheEntry(0, sEntryInfo, iSize)
  92.     If (hFile = 0) Then
  93.         If (Err.LastDllError = ERROR_NO_MORE_ITEMS) Then
  94.             GoTo done
  95.         End If
  96.         MsgBox "ERROR: FindFirstUrlCacheEntry - " & Err.LastDllError
  97.         Exit Sub
  98.     End If
  99.     Do
  100.         If (0 = DeleteUrlCacheEntry(sEntryInfo.szRestOfData(0))) _
  101.             And (Err.LastDllError <> 2) Then
  102.             Err.Clear
  103.         End If
  104.         iSize = BUFFERSIZE
  105.         If (0 = FindNextUrlCacheEntry(hFile, sEntryInfo, iSize)) And (Err.LastDllError <> ERROR_NO_MORE_ITEMS) Then
  106.             MsgBox "Error:  Unable to find the next cache entry - " & Err.LastDllError
  107.             Exit Sub
  108.         End If
  109.     Loop Until Err.LastDllError = ERROR_NO_MORE_ITEMS
  110. done:
  111.     MsgBox "cache cleared"
  112.     Command1.Enabled = True
  113. End Sub



dimmi se funziona.....ti dovrebbe cancellare la cache ogni volta che premi il bottone

mi da errore An error occurred enumerating the cache groups87 - piter123 - 25/08/11 18:18
PM
Avatar
gibra (Normal User)
Pro


Messaggi: 155
Iscritto: 16/04/2009

Up
0
Down
V
Segnala al moderatore
Postato alle 15:02
Giovedė, 04/08/2011

PM