Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
FTP control and progress bar
Message
De
23/10/2001 17:38:10
 
 
À
23/10/2001 14:58:18
Information générale
Forum:
Visual FoxPro
Catégorie:
Applications Internet
Divers
Thread ID:
00572230
Message ID:
00572346
Vues:
79
This message has been marked as the solution to the initial question of the thread.
>I am also tired of using 3rd party just to send a file to an FTP server. I can manipulate all that with MS INet control. However, as anyone found a way to show a progress bar?

Instead of FtpPutFile (or whatever wrapper function/method you're using) you can control the upload progress if you use a FtpOpenFile/InternetWriteFile combination. The following code demo this:
DECLARE INTEGER InternetOpen in WinINet.dll ;
  STRING cAgent, INTEGER nType, STRING cProxy, STRING cBypass, INTEGER nFlags
DECLARE INTEGER InternetCloseHandle in WinINet.dll ;
  INTEGER nInternetHandle
DECLARE INTEGER InternetConnect in WinINet.dll ;
  INTEGER nInternetSession, STRING cServer, INTEGER nPort, ;
  STRING cUserName, STRING cPassword, INTEGER nService, INTEGER nFlags, INTEGER nContext
DECLARE INTEGER FtpSetCurrentDirectory IN WinINet.dll ;
  INTEGER nFtpSession, STRING cDirectory
DECLARE INTEGER FtpOpenFile IN WinINet.dll ;
  INTEGER nFtpSession, STRING lpszFileName, INTEGER nAccess, INTEGER NFlags, ;
  INTEGER nContext
DECLARE INTEGER InternetWriteFile IN WinINet.dll ;
  INTEGER nFile, STRING cBuffer, ;
  INTEGER nToWrite, INTEGER @ nWritten

lnSession = InternetOpen("Wininet",0,.NULL.,.NULL.,0)

* set as appropriate
lcServer = "myserver"
lcUserName = "login"
lcPassword = "password"
lcDir = "/public"
lcFile = "somefile.bin"
lcLocalFile = "d:\temp\somefile.bin"
lnBufferSize = 1024

IF lnSession!=0
  lnFTPSession = InternetConnect(lnSession,lcServer,21,lcUserName,lcPassword,1,0x08000000,0)
  IF lnFTPSession!=0
    IF FtpSetCurrentDirectory(lnFTPSession,lcDir)!=0

      * open the file for upload (both local and remote)
      lnRemote = FtpOpenFile(lnFTPSession,lcFile,0x40000000,2,0)
      lnLocal = FOPEN(lcLocalFile,0)

      IF lnRemote!=0 AND lnLocal!=-1

        * we got valid handles, so we may start to send the file
        lnFileLength = FSEEK(lnLocal,0,2)
        FSEEK(lnLocal,0,0)
        lnUploaded = 0

        * while there is something to upload
        DO WHILE lnUploaded<lnFileLength
          lcBuffer = FREAD(lnLocal,lnBufferSize)
          lnWritten = 0
          InternetWriteFile(lnRemote,lcBuffer,LEN(lcBuffer),@lnWritten)
          lnUploaded = lnUploaded+LEN(lcBuffer)
          * show progress (pretend this is a progress bar...)
          WAIT WINDOW "Uploaded so far: "+LTRIM(STR((lnUploaded*100/lnFileLength)))+"%" NOWAIT
        ENDDO

        * terminate upload
        InternetCloseHandle(lnRemote)
        FCLOSE(lnLocal)
        WAIT WINDOW "Done" NOCLEAR
      ENDIF

    ENDIF
    InternetCloseHandle(lnFTPSession)
  ENDIF
  InternetCloseHandle(lnSession)
ENDIF
bye
----------------------------------
António Tavares Lopes
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform