Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

export file over ftp 1

Status
Not open for further replies.

MrDontKnowNothing

Programmer
Jun 26, 2003
94
0
0
DE
hi guys and girls,

i'd like to export a table to a filesystem on another machine. i've tried something like this:

EXPORT TO ftp://132.123.44.99/CRP/shop/config/SQLSvr/MyXLS XL5

but it didn't work.
any clever ideas?

cheers

alex
 
You're getting close, though FTP:// isn't a standard windows file system convention like \\MachineName\sharename is...

If the other machine is on the local network and is a windows machine with a share you have access to, you can use the UNC name like that: \\MachineName\ShareName\Folder\Folder\file.ext

However, if you only have FTP access, then you first have to create a local file, then use FTP to send it to the other machine.

DSummZZZ wrote a nice faq on doing this at: faq184-3234
 
Alex,

I suggest you look at the Internet Transfer Control, which is one one of the ActiveX controls that comes with VFP. It allows you to do all kinds of FTP transfers.

I agree with Wgcs that that best way to do this is to create a local file first, then FTP it to the remote machine.

Mike


Mike Lewis
Edinburgh, Scotland
 
Uploading file to the FTP server using InternetWriteFile


Code:
#DEFINE INTERNET_INVALID_PORT_NUMBER   0 
#DEFINE INTERNET_OPEN_TYPE_DIRECT      1 
#DEFINE INTERNET_SERVICE_FTP           1 
#DEFINE FTP_TRANSFER_TYPE_ASCII        1 
#DEFINE FTP_TRANSFER_TYPE_BINARY       2 

#DEFINE GENERIC_READ    2147483648   && &H80000000 
#DEFINE GENERIC_WRITE   1073741824   && &H40000000 

    PUBLIC hOpen, hFtpSession 
    DO decl 

    * select FTP connection on which you an appropriate access level 
    * in all cases it can not be any "anonymous" access 
    IF connect2ftp ("ftp.???.???", "???", "???") 
        lcSourcePath = "C:\Temp\"       && local source directory 
        lcTargetPath = "ftptest/"       && ftp destination directory 
        lnFiles = ADIR (arr, lcSourcePath + "*.html") 

        FOR lnCnt=1 TO lnFiles 
            lcSource = lcSourcePath + LOWER (arr [lnCnt, 1]) 
            lcTarget = lcTargetPath + LOWER (arr [lnCnt, 1]) 
            ? lcSource + " -> " + lcTarget 
            ?? local2ftp (hFtpSession, lcSource, lcTarget) 
        ENDFOR 

        = InternetCloseHandle (hFtpSession)   
        = InternetCloseHandle (hOpen) 
    ENDIF 

PROCEDURE  decl 
    DECLARE INTEGER InternetOpen IN wininet.dll;   
        STRING  sAgent,;   
        INTEGER lAccessType,;   
        STRING  sProxyName,;   
        STRING  sProxyBypass,;   
        STRING  lFlags   
        
    DECLARE INTEGER InternetCloseHandle IN wininet.dll INTEGER hInet   

    DECLARE INTEGER InternetConnect IN wininet.dll;   
        INTEGER hInternetSession,;   
        STRING  sServerName,;   
        INTEGER nServerPort,;   
        STRING  sUsername,;   
        STRING  sPassword,;   
        INTEGER lService,;   
        INTEGER lFlags,;   
        INTEGER lContext   

    DECLARE INTEGER FtpOpenFile IN wininet.dll; 
            INTEGER hFtpSession,; 
            STRING  sFileName,; 
            INTEGER lAccess,; 
            INTEGER lFlags,; 
            INTEGER lContext 

    DECLARE INTEGER InternetWriteFile IN wininet.dll; 
        INTEGER   hFile,; 
        STRING  @ sBuffer,; 
        INTEGER   lNumBytesToWrite,; 
        INTEGER @ dwNumberOfBytesWritten 
RETURN 

FUNCTION  connect2ftp (strHost, strUser, strPwd) 
    * open access to Inet functions   
    hOpen = InternetOpen ("vfp", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0)   

    IF hOpen = 0   
        ? "Unable to get access to WinInet.Dll" 
        RETURN .F. 
    ENDIF 

    * connect to FTP   
    hFtpSession = InternetConnect (hOpen, strHost, INTERNET_INVALID_PORT_NUMBER,;   
        strUser, strPwd, INTERNET_SERVICE_FTP, 0, 0)   

    IF hFtpSession = 0   
    * close access to Inet functions and exit   
        = InternetCloseHandle (hOpen)   
        ? "FTP " + strHost + " is not available" 
        RETURN .F. 
    ELSE   
        ? "Connected to " + strHost + " as: [" + strUser + ", *****]"   
    ENDIF   
RETURN .T. 

FUNCTION local2ftp (hConnect, lcSource, lcTarget) 
* copying local file to the remote target 
    hSource = FOPEN (lcSource) 
    IF (hSource = -1) 
        RETURN -1 
    ENDIF 

    * this call creates a new remote file 
    hTarget = FtpOpenFile(hConnect, lcTarget, GENERIC_WRITE,; 
        FTP_TRANSFER_TYPE_BINARY, 0) 
    IF hTarget = 0 
        = FCLOSE (hSource) 
        RETURN -2 
    ENDIF 

    lnBytesWritten = 0 
    lnChunkSize = 256    && 128, 512 and even 16384 are good 

    DO WHILE Not FEOF(hSource) 
        lcBuffer = FREAD (hSource, lnChunkSize) 
        lnLength = Len(lcBuffer) 
        IF lnLength > 0 
            IF InternetWriteFile (hTarget, @lcBuffer, lnLength, @lnLength) = 1 
                lnBytesWritten = lnBytesWritten + lnLength 
                * at this point you can display the progress 
                * and test events: keyboard, mouse etc. 
                * to decide on aborting the upload 
                ?? "·"    && you can put link to a progress bar here instead 
            ELSE 
                EXIT 
            ENDIF 
        ELSE 
            EXIT 
        ENDIF 
    ENDDO 
    = InternetCloseHandle (hTarget) 
    = FCLOSE (hSource) 
RETURN  lnBytesWritten

[sub]Code provided by Anatoliy Mogylevets
[/sub]



Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top