FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Upload to FTP
Posts: 408
Joined: Sun Nov 06, 2005 03:55 PM
Upload to FTP
Posted: Thu Jan 21, 2016 10:07 PM

Is there a way in Harbour + Fivewin to upload a file via FTP using the CreatObject() Function?
Currently we are doing something kind of like dynamically building a batch file, executing it, and reading the response from a piped file.
So we have to loop and wait for the file system to release the response file to check for errors.
I was hoping for a better way.

Thanks,

Byron ...

Thanks,

Byron Hopp

Matrix Computer Services
Posts: 408
Joined: Sun Nov 06, 2005 03:55 PM
Re: Upload to FTP
Posted: Fri Jan 22, 2016 09:36 AM

Where do I find tIpClient() I see it on this board, but I do not find it in the source directory of FiveWin, is this Harbour, xHarbour?
Does Fivewin have an FTP client that can upload a file via FTP that is RFC compliant?

Thanks,

Byron ...

Thanks,

Byron Hopp

Matrix Computer Services
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Upload to FTP
Posted: Fri Jan 22, 2016 05:17 PM
Some elements from my code ... you can piece it together from these I believe:

Code (fw): Select all Collapse
PRIVATE iDLL := LoadLibrary( "wininet.dll" )

*************************************************

FUNCTION sendfile

    LOCAL mCLinkFt := "ftp.yoursite.com"
    LOCAL mCLinkUn := "username"
    LOCAL mCLinkPw :=  "password"

    // Establish connection and transfer data
    hInternet := InternetOpen( "ABC",1,0,0,0 )
    hconnect := InterNetConnect( hInternet, mCLinkFt, 0, mCLinkUn, mCLinkPw, 1, INTERNET_FLAG_PASSIVE, 0 )
    IF hconnect == 0
        IF FTPPutFile( hConnect, cUpFile, cNameFile, 0, 0 )
            MsgInfo( "Uploaded" )
        ELSE
            MsgInfo( "Failed" )
        ENDIF
    ENDIF

    // Close connections and release library
    INETCLOSEHANDLE( hConnect )
    INETCLOSEHANDLE( hInternet )

RETURN NIL
**************************************************
DLL32 FUNCTION InternetOpen( cAgent AS LPSTR, nAccessType AS DWORD, cProxyName AS LPSTR, cProxyBypass AS LPSTR, nFlags ;
    AS DWORD ) AS LONG PASCAL FROM "InternetOpenA" LIB iDLL

DLL32 FUNCTION INETCLOSEHANDLE( hInternet AS LONG ) AS BOOL;
    PASCAL FROM "InternetCloseHandle" LIB iDLL

DLL32 FUNCTION FTPGETFILE( hConnect AS LONG, cRemoteFile AS LPSTR, cNewFile AS LPSTR, nFailIfExists AS LONG, ;
    nFlagsAndAttribs AS DWORD, nFlags AS DWORD, @nContext AS PTR ) AS BOOL PASCAL FROM "FtpGetFileA" LIB iDLL

DLL32 FUNCTION FtpPutFile( hFTP AS LONG, cFileName AS LPSTR, cDestFile AS LPSTR,;
    n1 AS LONG, n2 AS LONG ) AS BOOL PASCAL ;
    FROM "FtpPutFileA" LIB iDLL

DLL32 FUNCTION InternetConnect( hSession AS LONG, cHost AS LPSTR, nPort AS LONG,;
    cUserName AS LPSTR, cPassword AS LPSTR, n4 AS LONG, n5 AS LONG,;
    n6 AS LONG ) AS LONG PASCAL ;
    FROM "InternetConnectA" LIB iDLL
Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 408
Joined: Sun Nov 06, 2005 03:55 PM
Re: Upload to FTP
Posted: Fri Jan 22, 2016 06:16 PM

Thank you Tim, I have downloaded iDll.dll and I am going to give it a shot.

Thanks,

Byron Hopp

Matrix Computer Services
Posts: 3022
Joined: Fri Oct 07, 2005 01:45 PM
Re: Upload to FTP
Posted: Fri Jan 22, 2016 06:47 PM

iDll is just the handle for the wininet.dll provided in Windows. It should be visible in any system where WIndows in installed.

Tim Stone
http://www.MasterLinkSoftware.com
http://www.autoshopwriter.com
timstone@masterlinksoftware.com
Using: FWH 23.10 with Harbour 3.2.0 / Microsoft Visual Studio Community 2022-24 32/64 bit
Posts: 408
Joined: Sun Nov 06, 2005 03:55 PM
Re: Upload to FTP
Posted: Fri Jan 29, 2016 05:42 PM
I am attempting to use the code posted by Tim for FTP. However I need an additional function which seems to be available in WinINet.dll. The function I need is FtpSetCurrentDirectory(). My question is how do you know how to write the "DLL32" declarations.

DLL32 Function FtpSetCurrentlyDirectory( hFtp AS LONG, cDirName AS LPSTR ) AS BOOL PASCAL FROM "FtpSetCurrentDirecotry" LIB iDLL

How do you determine what goes in the FROM parameter, FtpSetCurrentDirectory, FtpSetCurrentDirectorya, something else?

Thank you,

Byron ...
Thanks,

Byron Hopp

Matrix Computer Services
Posts: 9022
Joined: Thu Oct 06, 2005 08:17 PM
Re: Upload to FTP
Posted: Tue Feb 02, 2016 09:59 AM
byron.hopp wrote:I am attempting to use the code posted by Tim for FTP. However I need an additional function which seems to be available in WinINet.dll. The function I need is FtpSetCurrentDirectory(). My question is how do you know how to write the "DLL32" declarations.

DLL32 Function FtpSetCurrentlyDirectory( hFtp AS LONG, cDirName AS LPSTR ) AS BOOL PASCAL FROM "FtpSetCurrentDirecotry" LIB iDLL

How do you determine what goes in the FROM parameter, FtpSetCurrentDirectory, FtpSetCurrentDirectorya, something else?

Thank you,

Byron ...


It's the name of the API:

https://msdn.microsoft.com/it-it/library/windows/desktop/aa384178(v=vs.85).aspx

Additionally, you have to add A

Code (fw): Select all Collapse
FtpSetCurrentDirectoryA


if a character string parameter is used by the function.

EMG
Posts: 408
Joined: Sun Nov 06, 2005 03:55 PM
Re: Upload to FTP
Posted: Tue Feb 02, 2016 05:32 PM

Thanks EMG, the "A" is the trick. Got the whole thang working now.

Byron ...

Thanks,

Byron Hopp

Matrix Computer Services

Continue the discussion