Upload to FTP

Upload to FTP

Postby byron.hopp » 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
byron.hopp
 
Posts: 382
Joined: Sun Nov 06, 2005 3:55 pm
Location: Southern California, USA

Re: Upload to FTP

Postby byron.hopp » Fri Jan 22, 2016 9: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
byron.hopp
 
Posts: 382
Joined: Sun Nov 06, 2005 3:55 pm
Location: Southern California, USA

Re: Upload to FTP

Postby TimStone » Fri Jan 22, 2016 5:17 pm

Some elements from my code ... you can piece it together from these I believe:

Code: Select all  Expand view


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
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Upload to FTP

Postby byron.hopp » Fri Jan 22, 2016 6: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
byron.hopp
 
Posts: 382
Joined: Sun Nov 06, 2005 3:55 pm
Location: Southern California, USA

Re: Upload to FTP

Postby TimStone » Fri Jan 22, 2016 6: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
User avatar
TimStone
 
Posts: 2944
Joined: Fri Oct 07, 2005 1:45 pm
Location: Trabuco Canyon, CA USA

Re: Upload to FTP

Postby byron.hopp » Fri Jan 29, 2016 5: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
byron.hopp
 
Posts: 382
Joined: Sun Nov 06, 2005 3:55 pm
Location: Southern California, USA

Re: Upload to FTP

Postby Enrico Maria Giordano » Tue Feb 02, 2016 9: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: Select all  Expand view
FtpSetCurrentDirectoryA


if a character string parameter is used by the function.

EMG
User avatar
Enrico Maria Giordano
 
Posts: 8710
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia

Re: Upload to FTP

Postby byron.hopp » Tue Feb 02, 2016 5:32 pm

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

Byron ...
Thanks,
Byron Hopp
Matrix Computer Services
byron.hopp
 
Posts: 382
Joined: Sun Nov 06, 2005 3:55 pm
Location: Southern California, USA


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 83 guests