hFile = FtpOpenFile(hConnection, strFileRemoto, GENERIC_READ,
FTP_TRANSFER_TYPE_BINARY, 0)
ret = FtpGetFileSize(hFile, lngSize)
lngSize � sempre -1
Che fare?
Daniele
prova con:
ret = FtpGetFileSize(hFile, ret)
immaginando che ret sia long
Segui questa discussione:
http://www.tek-tips.com/viewthread.cfm?qid=1553082&page=1
e questa:
http://vbnet.mvps.org/index.html?code/internet/ftpdownloadcallback.htm
e soprattutto questo esempio:
http://binaryworld.net/Main/CodeDetail.aspx?CodeId=3777
Ciao, Carlo
Cos'è che non funziona...?
Il lngSize rimane a -1 in quanto non viene istanziata la
connessione..., è infatti il tipico risultato di errore....!
Sei certo di arrivare via ftp al server...???
Hai i privilegi di Read sul file...?
Non hai detto nulla... quindi che dire...?
I Link suggerito da Carlo sono funzionanti in quanto li ho usati io
stesso per attivare
connessioni ftp con un Server aziendale, ma ho faticato un pò con i FW
ed i privilegi FTP_GET/PUT e la connessione in Anonimous del Server...
che spesso sono configurati male ed accettano solo quella....!!!!
@Alex
Ti riepilogo le dichiarazioni
Private Const INTERNET_FLAG_TRANSFER_BINARY = &H2
Private Const INTERNET_DEFAULT_FTP_PORT = 21 ' default
for FTP servers
Private Const FTP_TRANSFER_TYPE_BINARY = &H2
Private Const INTERNET_OPEN_TYPE_DIRECT = 1 ' direct
to net
Private Const INTERNET_DEFAULT_FTP_PORT = 21 ' default
for FTP servers
Private Const INTERNET_FLAG_PASSIVE = &H8000000 ' used for
FTP connections
Private Declare Function FTPGetFile Lib "wininet.dll" _
Alias "FtpGetFileA" _
(ByVal hConnect As Long, _
ByVal lpszRemoteFile As String, _
ByVal lpszNewFile As String, _
ByVal fFailIfExists As Long, _
ByVal dwFlagsAndAttributes As Long, _
ByVal dwFlags As Long, _
ByRef dwContext As Long) As Long
Private Declare Function FtpOpenFile Lib "wininet" _
Alias "FtpOpenFileA" _
(ByVal hConnect As Long, _
ByVal lpszFileName As String, _
ByVal dwAccess As Long, _
ByVal dwFlags As Long, _
ByVal dwContext As Long) As Long
Private Const GENERIC_READ As Long = &H80000000
Private Declare Function FtpGetFileSize Lib "wininet.dll" _
(ByVal hFile As Long, _
ByRef lpdwFileSize As Long) As Long
hOpen = _
InternetOpen("Fantasia FTP", _
INTERNET_OPEN_TYPE_DIRECT, _
vbNullString, _
vbNullString, _
INTERNET_FLAG_PASSIVE)
If hOpen = 0 Then
EseguiFTP = False
GoTo Exit_EseguiFTP
End If
'Apre la connesione con l'FTP Server
hConnection = _
InternetConnect(hOpen, _
"IPSERVER", _
INTERNET_DEFAULT_FTP_PORT, _
"user", _
"password", _
INTERNET_SERVICE_FTP, _
INTERNET_FLAG_PASSIVE, _
0)
If hConnection = 0 Then
meblnErroriComando = True
EseguiFTP = False
GoTo Exit_EseguiFTP
End If
Dim hFile As Long
hFile = FtpOpenFile(hConnection, "RemoteFile", GENERIC_READ,
FTP_TRANSFER_TYPE_BINARY, 0)
'qui ho verificao che hfile � sempre diverso da 0
If hFile = 0 Then
EseguiFTP = False
GoTo Exit_EseguiFTP
End If
Dim sizeH As Long
Dim sizeL As Long
Dim size As long
Dim maxSize as long
maxSize = 2 ^ 31 - 1
sizeH = 0
sizeL = FtpGetFileSize(hFile, sizeH) 'non funge
debug.print sizeL, sizeH, sizeH*maxsize+sizeL 'se le dimensioni sono
> 2^31-1
size = FtpGetFileSize(hFile, size) 'non funge
debug.print size
Invece lngRet = FTPGetFile(hConnection, "RemoteFile", "LocalFile" &
meStrNomeFile, False, 0, FTP_TRANSFER_TYPE_BINARY, 0)
funziona benissimo sia in modo passive, che asincrono
Di pi� non so'
Daniele
Penso che il probema sia questo:
200 Representation type is binary IMAGE.
227 Entering Passive Mode (192,168,0,250,19,222).
500 Subcommand SIZE not valid.
150 Retrieving member RemoteFile in file RemoteFile in library LibreriaDati.
Il server non riconosce il subcommand size, ma il file � aperto regorlmente
Credo non ci siano strate
Dovr� abbandonare WinInet ed eseguire via dos
Da dos si possono inviare comandi batch nativi del server.
Grazie