Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Send file ftp
Message
From
01/11/2005 11:16:57
 
 
To
01/11/2005 10:49:28
General information
Forum:
Visual FoxPro
Category:
Internet applications
Title:
Environment versions
Visual FoxPro:
VFP 8 SP1
OS:
Windows 2000 SP4
Network:
Windows NT
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01064010
Message ID:
01064032
Views:
35
Debra:

With FTP I eventually used WinInet calls and had better luck than using 3rd party stuff. Not that there's anything bad with the 3rd party FTP classes, just that FTP wasn't all that difficult. Below is a (rather lengthy) method I copied that FTPs a file. You may get some use out of it.

Regards,

Scott
FUNCTION SendFile
    PARAMETERS px_Dummy1, px_Dummy2, px_Dummy3, px_Dummy4, px_Dummy5
    LOCAL lc_FTPSendTargetName, ln_RetCode, ln_OldnConnectTimeOut, ln_OldWinInetSetTimeout, ;
          lc_FTPResult, ln_FTPResultSize, lc_FTP_put_command
    lhInternetConnection = 0000
    lhFTPSession         = 0000
    lcDirectoryName      = SPACE(01)
    DECLARE INTEGER InternetOpen ;
         IN         WinInet.dll;
         STRING     lpszAgent,;
         INTEGER    dwAccessType,;
         STRING     lpszProxyName,;
         STRING     lpszProxyBypass,;
         INTEGER    dwFlags
    DECLARE INTEGER InternetConnect ;
         IN         WinInet.dll ;
         INTEGER    hIPHandle,;
         STRING     lpszServer,;
         INTEGER    dwPort,;
         STRING     lpszUserName,;
         STRING     lpszPassWord,;
         INTEGER    dwServiceFlags,;
         INTEGER    dwReserved,;
         INTEGER    dwReserved
    DECLARE INTEGER InternetCloseHandle;
           IN       WinInet.dll;
           INTEGER  hIPSession
    DECLARE INTEGER FtpSetCurrentDirectory;
         IN         WinInet.dll;
         INTEGER    lhFTPSession,;
         STRING     lpszDirectory
    DECLARE INTEGER FtpPutFile;
         IN         WinInet.dll;
         INTEGER    hConnect,;
         STRING     lpszSendFileName,;
         STRING     lpszTargetFileName,;
         INTEGER    dwFlags,;
         INTEGER    dwReserved
    DECLARE INTEGER InternetCloseHandle ;
         IN         WinInet.dll ;
         INTEGER    hInternet
    DECLARE INTEGER FtpOpenFile ;
         IN         WinInet.dll ;
         INTEGER    hIPSession,;
         STRING     @lpszFileName,;
         INTEGER    dwAcessFlags,;
         INTEGER    dwServiceFlags,;
         INTEGER    dwContext
    DECLARE INTEGER InternetWriteFile ;
         IN         WinInet.dll ;
         INTEGER    hFTPHandle,;
         STRING     lcBuffer,;
         INTEGER    cbBuffer,;
         INTEGER    @cbBuffer
    DECLARE INTEGER InternetSetOption;
         IN        WinInet.dll;
         INTEGER   hIPSession,;
         INTEGER   dwOption,;
         INTEGER   @lpBuffer,;
         LONG      lpdwBufferLength
    DECLARE INTEGER GetLastError;
         IN         Win32API
    lhInternetConnection = InternetOpen("PurchasingPC V2.0", 1, NULL, NULL, 0 )
    IF lhInternetConnection = 0
        This.ReturnText = "Unable to establish an internet connection"
        This.ReturnCode = 5026
        RETU( This.ReturnCode )
    ENDIF

    ***********************************************************************************************
    * Set timeout at 60 seconds since the FTP server seems to lag some of the times.
    ***********************************************************************************************
    lnTimeoutSeconds = 90 * 1000 && Convert seconds to milliseconds
    lnBufferLength   = 4
    lnResult = InternetSetOption( ;
        lhInternetConnection,;
        INTERNET_OPTION_CONNECT_TIMEOUT,;
        @lnTimeoutSeconds,;
        lnBufferLength )
    lnResult = InternetSetOption( ;
        lhInternetConnection,;
        INTERNET_OPTION_RECEIVE_TIMEOUT,;
        @lnTimeoutSeconds,;
        lnBufferLength )
    lnResult = InternetSetOption( ;
        lhInternetConnection,;
        INTERNET_OPTION_SEND_TIMEOUT,;
        @lnTimeoutSeconds,;
        lnBufferLength )
    IF lhInternetConnection = 0
        This.ReturnText = "Unable to establish an internet connection."
        This.ReturnCode = 5027
        RETU( This.ReturnCode )
    ENDIF
    lhFTPSession = InternetConnect(;
        lhInternetConnection,;
        This.FTPServerName,;
        This.PortNumber,;
        This.FTPUserName,;
        This.FTPPassword,;
        INTERNET_SERVICE_FTP,;
        0,0)
    IF lhFTPSession = 0
        This.ReturnText = "Unable to connect to FTP server at " +  This.FTPServerName + ":" + ALLTRIM( STR( This.PortNumber, 8, 0 ));
                        + This.gc_LF + "                Check your Setup."
        This.ReturnCode = 5031
        RETU( This.ReturnCode )
    ENDIF
    lcDirectoryName = "IN"
    lcDirectoryName = lcDirectoryName  + CHR(0)
    lnResult = FtpSetCurrentDirectory( lhFTPSession, @lcDirectoryName )
    IF lnResult <> 1
        This.ReturnText = "Unable to change to IN directory on FTP server."
        This.ReturnCode = 5028
        InternetCloseHandle( lhFTPSession )
        InternetCloseHandle( lhInternetConnection )
        lhFTPSession         = 0
        lhInternetConnection = 0
        RETU( This.ReturnCode )
    ENDIF
    lhFTPFile = FtpOpenFile( lhFTPSession, This.FTPSendTargetName,;
                GENERIC_WRITE,;
                INTERNET_FLAG_RELOAD + FTP_TRANSFER_TYPE_BINARY, 0)
    IF lhFTPFile = 0
        This.ReturnText = "Unable to open for output the FTP destination file."
        This.ReturnCode = 5029
        InternetCloseHandle( lhFTPSession )
        InternetCloseHandle( lhInternetConnection )
        lhFTPSession         = 0
        lhInternetConnection = 0
        RETU( This.ReturnCode )
    ENDIF
    *** Read the file from disk
    lhFile = FOPEN( This.FTPFileToSend )
    IF lhFile = -1
        This.ReturnText = "Source file does not exist or is in use by another."
        This.ReturnCode = 5030
        InternetCloseHandle( lhFTPSession )
        InternetCloseHandle( lhInternetConnection )
        lhFTPSession         = 0
        lhInternetConnection = 0
        RETU( This.ReturnCode )
    ENDIF
    tnBufferSize = 0
    lnBufferReads = 0
    lnFTPWorkBufferSize = 4096
    DO WHILE .T.
       *** Read one chunk at a time
       lcWriteBuffer = FRead(lhFile,lnFTPWorkBufferSize)
       IF LEN(lcWriteBuffer) = 0
          EXIT
       ENDIF
       *** And write out each chunk
       lnSize      = LEN(lcWriteBuffer)
       lnBytesRead = 0
       lnRetval=InternetWriteFile( lhFTPFile, lcWriteBuffer, lnSize, @lnBytesRead )
        IF (lnRetVal = 1 AND lnBytesRead = 0) OR (lnRetVal = 0)
           EXIT
        ENDIF
    ENDDO
    FCLOSE( lhFile )
    InternetCloseHandle( lhFTPFile )
    InternetCloseHandle( lhFTPSession )
    InternetCloseHandle( lhInternetConnection )
    lhFTPFile            = 0
    lhFTPSession         = 0
    lhInternetConnection = 0
    This.ReturnText = "Success"
    This.ReturnCode = 0001
RETURN( This.ReturnCode )
Scott Ramey
BDS Software
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform