I have a problem with the following code.
When I run it, the window with the progress bar opens but the bar is not refreshed (but the download runs correctly).
As soon as I click on the progress window, or just moving my mouse over it and the refresh starts.
What can be wrong? (I use PB 6.04)
You can run the code and download from my server. No problem. This file is publicly available anyway.
Thanks.
Code: Select all
Global ftp
Procedure myGetFile(file$)
download = 0
; we retrieve information on file in FTP
If ExamineFTPDirectory(ftp)
While NextFTPDirectoryEntry(ftp)
If FTPDirectoryEntryName(ftp) = file$
dateftp = Val(FormatDate("%yyyy%mm%dd",FTPDirectoryEntryDate(ftp)))
sizeftp = FTPDirectoryEntrySize(ftp)
Break
EndIf
Wend
FinishFTPDirectory(ftp)
EndIf
; we compare size and date between source and destination files
dateloc = 19000101
sizeloc = FileSize(file$)
; if local file not found
If sizeloc < 0
download = 1
Else
; if local file exists locally, we have to compare with file in FTP
If sizeloc >= 0
dateloc = Val(FormatDate("%yyyy%mm%dd", GetFileDate(file$, #PB_Date_Modified)))
EndIf
EndIf
; if file in FTP is more recent than local one
If dateftp > dateloc
download = 1
EndIf
; if file in FTP has same date but different size
If (dateftp = dateloc And sizeftp <> sizeloc)
download = 1
EndIf
If download = 1
If OpenWindow(0, #PB_Ignore, #PB_Ignore, 340, 50, "StatusBarProgress", #PB_Window_SystemMenu | #PB_Window_ScreenCentered | #PB_Window_SizeGadget)
statusbar = CreateStatusBar(0, WindowID(0))
If statusbar
AddStatusBarField(150)
AddStatusBarField(#PB_Ignore)
StatusBarText(0, 0, "Download in progress...")
StatusBarProgress(0, 1, 1)
EndIf
res = ReceiveFTPFile(ftp, file$, file$, #True)
If Not res
MessageRequester("Erreur", "cannot download " + file$)
CloseWindow(#PB_All)
ProcedureReturn
EndIf
Repeat
res = FTPProgress(ftp)
If WaitWindowEvent() = #PB_Event_CloseWindow
AbortFTPFile(ftp)
CloseWindow(#PB_All)
Break
EndIf
If res = #PB_FTP_Error
MessageRequester("Erreur", "Error downloading " + file$)
Break
EndIf
If res = #PB_FTP_Finished
Break
EndIf
If statusbar
StatusBarProgress(0, 1, Int(res / sizeftp * 100))
EndIf
Delay(100)
ForEver
FreeStatusBar(#PB_All)
ProcedureReturn
EndIf ; OpenWindow
EndIf ; download = 1
EndProcedure
#login = "login"
#password = "pass"
ftp = OpenFTP(#PB_Any, "ftp.domain.fr", #login, #password)
If Not ftp
MessageRequester("Erreur", "cannot connect")
End 1
EndIf
myGetFile("testfile.exe")
CloseFTP(ftp)