Uploading a file to webspace

Uploading a file to webspace

Postby driessen » Mon Sep 09, 2013 8:33 am

Hello,

I want my customers to be able to upload a file to a predefined webspace (it's usually a JPG- or a BMP-file for their logo in documents).
How can I obtain this in FWH?

Thanks a lot in advance.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Uploading a file to webspace

Postby Enrico Maria Giordano » Mon Sep 09, 2013 10:12 am

Driessen,

driessen wrote:Hello,

I want my customers to be able to upload a file to a predefined webspace (it's usually a JPG- or a BMP-file for their logo in documents).
How can I obtain this in FWH?

Thanks a lot in advance.


You have to use FTP.

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

Re: Uploading a file to webspace

Postby driessen » Mon Sep 09, 2013 1:18 pm

Thanks for your reply, Enrico.

I thought so already.

The samples in FWH about FTP are very simple.

I need an example to connect to a FTP-site, using a login and password.
Then I need to upload a file to a certain folder on the FTP-site.

Anyone an example?

Thanks a lot.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Uploading a file to webspace

Postby Enrico Maria Giordano » Mon Sep 09, 2013 1:38 pm

Driessen,

driessen wrote:Thanks for your reply, Enrico.

I thought so already.

The samples in FWH about FTP are very simple.

I need an example to connect to a FTP-site, using a login and password.
Then I need to upload a file to a certain folder on the FTP-site.

Anyone an example?

Thanks a lot.


Try the following function:

Code: Select all  Expand view
FUNCTION FTPWRITEFILE( cServerName, cRemotePath, cUserName, cPassword, cFileName )

    LOCAL hInternet, hConnect

    LOCAL lOk

    hInternet = INTERNETOPEN( "Anystring", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0 )
    hConnect = INTERNETCONNECT( hInternet, cServerName, INTERNET_DEFAULT_FTP_PORT, cUserName, cPassword, INTERNET_SERVICE_FTP, MODE, 0 )

    lOk = FTPPUTFILE( hConnect, cFileName, cRemotePath + "/" + CFILENAME( cFileName ), 0, 0 )

    INTERNETCLOSEHANDLE( hConnect )
    INTERNETCLOSEHANDLE( hInternet )

    RETURN lOk


#pragma BEGINDUMP

#include "windows.h"
#include "wininet.h"
#include "hbapi.h"


HB_FUNC( INTERNETOPEN )
{
    hb_retnl( ( LONG ) InternetOpen( hb_parc( 1 ), hb_parnl( 2 ), hb_parc( 3 ), hb_parc( 4 ), hb_parnl( 5 ) ) );
}


HB_FUNC( INTERNETCLOSEHANDLE )
{
    hb_retl( InternetCloseHandle( ( HINTERNET ) hb_parnl( 1 ) ) );
}


HB_FUNC( INTERNETCONNECT )
{
    hb_retnl( ( LONG ) InternetConnect( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), ( INTERNET_PORT ) hb_parnl( 3 ), hb_parc( 4 ), hb_parc( 5 ), hb_parnl( 6 ), hb_parnl( 7 ), hb_parnl( 8 ) ) );
}


HB_FUNC( FTPPUTFILE )
{
    hb_retl( FtpPutFile( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), hb_parc( 3 ), hb_parnl( 4 ), hb_parnl( 5 ) ) );
}

#pragma ENDDUMP


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

Re: Uploading a file to webspace

Postby driessen » Mon Sep 09, 2013 2:24 pm

Thanks a lot for the example, Enrico.

I'm going to try it out asap.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Uploading a file to webspace

Postby driessen » Mon Sep 09, 2013 2:38 pm

Enrico,

I got 2 problems.

1. If I build my test FTP.EXE, I got an error of an unresolved external symbol : "_HB_FUN_CFILENAME" referenced from FTP.OBJ.
I replaced the function CFILENAME() by ALLTRIM() and then building is ok.

2. When executing my test, I get an error : Variable does not exist : INTERNET_OPEN_TYPE_DIRECT.

What am I doing wrong?

Thanks.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Uploading a file to webspace

Postby Enrico Maria Giordano » Mon Sep 09, 2013 2:44 pm

Driessen,

driessen wrote:Enrico,

I got 2 problems.

1. If I build my test FTP.EXE, I got an error of an unresolved external symbol : "_HB_FUN_CFILENAME" referenced from FTP.OBJ.
I replaced the function CFILENAME() by ALLTRIM() and then building is ok.


You can't replace CFILENAME() with ALLTRIM()! CFILENAME() is a FWH function. Please look inside filename.prg.

driessen wrote:2. When executing my test, I get an error : Variable does not exist : INTERNET_OPEN_TYPE_DIRECT.


Code: Select all  Expand view
// Wininet constants

#define INTERNET_OPEN_TYPE_PRECONFIG                    0
#define INTERNET_OPEN_TYPE_DIRECT                       1
#define INTERNET_OPEN_TYPE_PROXY                        3
#define INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY  4

#define INTERNET_INVALID_PORT_NUMBER    0
#define INTERNET_DEFAULT_FTP_PORT       21
#define INTERNET_DEFAULT_GOPHER_PORT    70
#define INTERNET_DEFAULT_HTTP_PORT      80
#define INTERNET_DEFAULT_HTTPS_PORT     443
#define INTERNET_DEFAULT_SOCKS_PORT     1080

#define INTERNET_SERVICE_FTP     1
#define INTERNET_SERVICE_GOPHER  2
#define INTERNET_SERVICE_HTTP    3

#define INTERNET_FLAG_TRANSFER_ASCII  1
#define INTERNET_FLAG_TRANSFER_BINARY 2

#define INTERNET_FLAG_ACTIVE  0
#define INTERNET_FLAG_PASSIVE 134217728


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

Re: Uploading a file to webspace

Postby driessen » Mon Sep 09, 2013 3:06 pm

Enrico,

Building is ok now.

I have called the executable FTP.EXE

So I run FTP.EXE with these parameters : ftp://www.ma-consult.be content myusername mypassword test.txt

Server = ftp://www.ma-consult.be
Remote path = content
Username = myusername
Password = mypassword
File = test.txt

Unfortunately, nothing is happening. I can't find TEST.TXT on my FTP-server.

Do I have to mention "FTP://" in the servername?
Is the remote path ok?

Any idea why it doesn't work?

Thanks.
Regards,

Michel D.
Genk (Belgium)
_____________________________________________________________________________________________
I use : FiveWin for (x)Harbour v. 24.07 - Harbour 3.2.0 (February 2024) - xHarbour Builder (January 2020) - Bcc773
User avatar
driessen
 
Posts: 1422
Joined: Mon Oct 10, 2005 11:26 am
Location: Genk, Belgium

Re: Uploading a file to webspace

Postby Enrico Maria Giordano » Mon Sep 09, 2013 3:18 pm

Driessen,

Please send me a private mail with your sample attached and I'll test it here.

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


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: Google [Bot] and 92 guests