Page 1 of 1

Upload to FTP

Posted: Thu Jan 21, 2016 10:07 pm
by byron.hopp
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 ...

Re: Upload to FTP

Posted: Fri Jan 22, 2016 9:36 am
by byron.hopp
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 ...

Re: Upload to FTP

Posted: Fri Jan 22, 2016 5:17 pm
by TimStone
Some elements from my code ... you can piece it together from these I believe:

Code: Select all | Expand



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



 

Re: Upload to FTP

Posted: Fri Jan 22, 2016 6:16 pm
by byron.hopp
Thank you Tim, I have downloaded iDll.dll and I am going to give it a shot.

Re: Upload to FTP

Posted: Fri Jan 22, 2016 6:47 pm
by TimStone
iDll is just the handle for the wininet.dll provided in Windows. It should be visible in any system where WIndows in installed.

Re: Upload to FTP

Posted: Fri Jan 29, 2016 5:42 pm
by byron.hopp
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 ...

Re: Upload to FTP

Posted: Tue Feb 02, 2016 9:59 am
by Enrico Maria Giordano
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: Select all | Expand

FtpSetCurrentDirectoryA


if a character string parameter is used by the function.

EMG

Re: Upload to FTP

Posted: Tue Feb 02, 2016 5:32 pm
by byron.hopp
Thanks EMG, the "A" is the trick. Got the whole thang working now.

Byron ...