Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Get Current Directory in Ftp Class
Message
De
09/07/2003 05:07:43
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00807877
Message ID:
00808372
Vues:
12
>Greg Thanx...
>
>But i've some other question...
>How to show a hashing status when we upload or download file in FTP ?
>
>IN Ftp - dos when we try to download / upload file, if the hash status is on,
>there's appear a '#' continuisly...
>
>By that idea i want to implement it in VFP..
>
>CAuse when i start to deal with a big file (Mbytes), there's like no progress showing in screen...
>I'm afraid that the user might suspect that it was Hang..
>
>thx for your help again..
>
>thx

Tut,

You can do so using InternetReadFile()/InternetWriteFile().
If you donwload a file, you can use FtpGetFileSize() to get its size. Note that FtpGetFileSize() is not always successful

Am including send + get from my class. Think you can take it from there
&& ftpSendFile
lparameters	Source, Destination


fd = fopen(Source)

if( fd < 0 )
	wait window nowait 'Cannot open ' + Source
	return FALSE
endif

local fd_ftp

fd_ftp = FtpOpenFile(this.ftpHandle, Destination, GENERIC_WRITE, ;
                       FTP_TRANSFER_TYPE_BINARY + INTERNET_FLAG_RELOAD,0)


if( empty(fd_ftp) )
	wait window nowait 'cannot open RemoteFile ' + Destination
	=fclose(fd)
	return FALSE
endif

local Success, n, t, nbytes, buf
Success = TRUE
	
t = therm(fseek(fd,0,2)/1024, 'ftp ' + Source + ' >> ' + Destination )
=fseek(fd, 0, 0)
	
n = 0

do while !feof(fd)
	buf = fread(fd, 8*1024)
	
	nBytes = 0
	if( !empty(InternetWriteFile(fd_ftp, Buf, len(buf), @nbytes )) )
		if( len(buf) == nBytes )
			&& ok
			n = n + nBytes
			=t.Update(n/1024)
		else
			wait window nowait 'write error, bytes <>'
			Success = FALSE
			exit
		endif
	else
		wait window nowait 'write error'
		Success = FALSE
		exit
	endif
enddo
=fclose(fd)

=InternetCloseHandle(fd_ftp)


return Success
&& ftpGetfile
lparameters	Source, Destination

local fd_ftp

fd_ftp = FtpOpenFile(this.ftpHandle, Source, GENERIC_READ,;
                       INTERNET_FLAG_RELOAD + FTP_TRANSFER_TYPE_BINARY,0)

if( empty(fd_ftp) )
	wait window nowait 'cannot open remote file ' + Source
	return FALSE
endif



local fd
fd = fcreate(Destination)

if( fd < 0 )
	wait window nowait 'cannot create ' + Destination
	=InternetCloseHandle(fd_ftp)
	return FALSE
endif


local FileSize, fs1, fs2, HaveFileSize
fs2 = 0

fs1 = FtpGetFileSize( fd_ftp, @fs2)

FileSize = fs2 * 2^32 + fs1

HaveFileSize = !(FileSize < 0 )

if( !HaveFileSize )
	FileSize = 0
endif


local t, n
n = 0

t = therm(FileSize/1024, 'ftp ' + Destination + ' << ' + Source)

local buf, BytesRead, bufSize, sts

do while TRUE
	buf = space(64*1024)
	BytesRead = 0
	BufSize = len(Buf)
	
	sts = InternetReadFile(fd_ftp, @Buf, BufSize, @BytesRead)
	
	if( sts = 0 )
		exit
	else
		if( BytesRead = 0 )
			exit
		else
			n = n + BytesRead
			=iif(HaveFileSize, t.Update(n/1024), t.Update(n/1024, '', n/1024) )
			if( fwrite(fd, buf, BytesRead) <> BytesRead )
				wait window nowait 'Write error'
				exit
			endif
			
		endif
	endif
enddo

=fclose(fd)
=InternetCloseHandle(fd_ftp)

if( !HaveFileSize )
	FileSize = n
endif

return	( n == FileSize )
Gregory
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform