URLDownloadToFile

URLDownloadToFile

Postby Jeff Barnes » Tue Nov 03, 2015 3:50 pm

I'm using URLDownloadToFile to download a file from my website and it works well.
How can I delete the file from my website after I've downloaded it?
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: URLDownloadToFile

Postby Enrico Maria Giordano » Tue Nov 03, 2015 3:55 pm

Jeff Barnes wrote:I'm using URLDownloadToFile to download a file from my website and it works well.
How can I delete the file from my website after I've downloaded it?


Use a script that you can invoke as an url to delete the file.

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

Re: URLDownloadToFile

Postby Jeff Barnes » Tue Nov 03, 2015 4:19 pm

Hi Enrico,

Not sure what you mean ... do you have a sample?
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: URLDownloadToFile

Postby Enrico Maria Giordano » Tue Nov 03, 2015 5:56 pm

You can write a script like this:

Code: Select all  Expand view
<%
  Set fs = Server.CreateObject( "Scripting.FileSystemObject" )

  fs.DeleteFile( Server.MapPath( "/yourpath" ) + "/" + Request( "Filename" ) )

  Set fs = Nothing

  Response.Redirect "deleteok.htm"
%>


Then you can invoke it with something like

http://yourdomain/thescript.asp?Filename=myfile

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

Re: URLDownloadToFile

Postby Jeff Barnes » Tue Nov 03, 2015 6:57 pm

When I use the "http://yourdomain/thescript.asp?Filename=myfile" in my browser it just opens and shows the contents of the .asp file in the browser.
The file does not get deleted :(
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: URLDownloadToFile

Postby Enrico Maria Giordano » Tue Nov 03, 2015 7:06 pm

Probably your server can't execute ASP scripts. You can use PHP (I'm not familiar with PHP, sorry):

<?php
unlink( $_SERVER[ "yourpath" ] . $_GET[ "Filename" ] ) or die( "Error" );
echo "OK";
?>

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

Re: URLDownloadToFile

Postby Jeff Barnes » Tue Nov 03, 2015 7:34 pm

Thanks Enrico.
Using PHP worked :)
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: URLDownloadToFile

Postby Jeff Barnes » Tue Nov 03, 2015 7:54 pm

Once last question....

I use ShellExecute() to open the url.
Is there any way to not have the browser show to the user?

I tried setting the last parameter to 0 but it still shows.

ShellExec(0,,"Http.......",,,0)
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: URLDownloadToFile

Postby Enrico Maria Giordano » Tue Nov 03, 2015 8:37 pm

Use this:

Code: Select all  Expand view
FUNCTION RUNURL( cUrl )

    LOCAL oUrl, oCli

    LOCAL lOk := .F.

    BEGIN SEQUENCE
        oUrl = TUrl():New( cUrl )

        IF EMPTY( oUrl ); BREAK; ENDIF

        oCli = TIPClientHttp():New( oUrl )

        IF EMPTY( oCli ); BREAK; ENDIF

        IF !oCli:Open(); BREAK; ENDIF

        ? oCli:ReadAll()

        lOk = "OK" $ UPPER( oCli:cReply )

        oCli:Close()
    END SEQUENCE

    RETURN lOk


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

Re: URLDownloadToFile

Postby Jeff Barnes » Tue Nov 03, 2015 8:45 pm

Thanks Enrico.
I will use this code instead of ShellExecute :D
Thanks,
Jeff Barnes

(FWH 16.11, xHarbour 1.2.3, Bcc730)
User avatar
Jeff Barnes
 
Posts: 929
Joined: Sun Oct 09, 2005 1:05 pm
Location: Ontario, Canada

Re: URLDownloadToFile

Postby RAMESHBABU » Wed Nov 04, 2015 1:12 am

Mr.Enrico,

Similarly, Can you please guide me how to upload a file to a website.

Thanks,

-Ramesh Babu
User avatar
RAMESHBABU
 
Posts: 615
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: URLDownloadToFile

Postby Enrico Maria Giordano » Wed Nov 04, 2015 9:11 am

Do you mean, upload via http form and "file" type HTML control?

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

Re: URLDownloadToFile

Postby RAMESHBABU » Wed Nov 04, 2015 1:50 pm

Mr.Enrico,

I need to upload a set of files to my FTP Site. The file types may be .DBF/.FPT/.CDX
or .EXE sometimes.

I think I could explain what I need.

Regards,

-Ramesh Babu
User avatar
RAMESHBABU
 
Posts: 615
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Re: URLDownloadToFile

Postby Enrico Maria Giordano » Wed Nov 04, 2015 2:51 pm

Here it is:

Code: Select all  Expand view
#include "Fivewin.ch"


//
// File attributes
//

#define FILE_ATTRIBUTE_READONLY  1
#define FILE_ATTRIBUTE_HIDDEN    2
#define FILE_ATTRIBUTE_SYSTEM    4
#define FILE_ATTRIBUTE_DIRECTORY 16
#define FILE_ATTRIBUTE_ARCHIVE   32
#define FILE_ATTRIBUTE_NORMAL    128
#define FILE_ATTRIBUTE_TEMPORARY 256


//
// access types for InternetOpen()
//

#define INTERNET_OPEN_TYPE_PRECONFIG                    0   // use registry configuration
#define INTERNET_OPEN_TYPE_DIRECT                       1   // direct to net
#define INTERNET_OPEN_TYPE_PROXY                        3   // via named proxy
#define INTERNET_OPEN_TYPE_PRECONFIG_WITH_NO_AUTOPROXY  4   // prevent using java/script/INS


//
// manifests
//

#define INTERNET_INVALID_PORT_NUMBER    0           // use the protocol-specific default

#define INTERNET_DEFAULT_FTP_PORT       21          // default for FTP servers
#define INTERNET_DEFAULT_GOPHER_PORT    70          //    "     " gopher "
#define INTERNET_DEFAULT_HTTP_PORT      80          //    "     " HTTP   "
#define INTERNET_DEFAULT_HTTPS_PORT     443         //    "     " HTTPS  "
#define INTERNET_DEFAULT_SOCKS_PORT     1080        // default for SOCKS firewall servers.


//
// service types for InternetConnect()
//

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


//
// flags for FTP
//

#define INTERNET_FLAG_TRANSFER_ASCII  1
#define INTERNET_FLAG_TRANSFER_BINARY 2


FUNCTION MAIN()

    LOCAL hInternet, hConnect

    hInternet = INTERNETOPEN( "Anystring", INTERNET_OPEN_TYPE_DIRECT, 0, 0, 0 )

    hConnect = INTERNETCONNECT( hInternet, "myftpaddress", INTERNET_INVALID_PORT_NUMBER, "myuserid", "mypassword", INTERNET_SERVICE_FTP, 0, 0 )

    ? FTPGETFILE( hConnect, "/emagsoftware.it/test/atest.prg", "atest.prg", 0, FILE_ATTRIBUTE_ARCHIVE, 0, 0 )

//    ? FTPPUTFILE( hConnect, "atest.prg", "/emagsoftware.it/test/atest.prg", 0, 0 )

    INTERNETCLOSEHANDLE( hConnect )

    INTERNETCLOSEHANDLE( hInternet )

    RETURN NIL


#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( FTPGETFILE )
{
    hb_retl( FtpGetFile( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), hb_parc( 3 ), hb_parl( 4 ), hb_parnl( 5 ), hb_parnl( 6 ), hb_parnl( 7 ) ) );
}


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


HB_FUNC( FTPDELETEFILE )
{
    hb_retl( FtpDeleteFile( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ) ) );
}


HB_FUNC( FTPCREATEDIRECTORY )
{
    hb_retl( FtpCreateDirectory( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ) ) );
}


HB_FUNC( FTPREMOVEDIRECTORY )
{
    hb_retl( FtpRemoveDirectory( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ) ) );
}


HB_FUNC( FTPFINDFIRSTFILE )
{
    hb_retnl( ( LONG ) FtpFindFirstFile( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ), ( WIN32_FIND_DATA * ) hb_parc( 3 ), hb_parnl( 4 ), hb_parnl( 5 ) ) );
}


HB_FUNC( INTERNETFINDNEXTFILE )
{
    hb_retl( InternetFindNextFile( ( HINTERNET ) hb_parnl( 1 ), hb_parc( 2 ) ) );
}

#pragma ENDDUMP


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

Re: URLDownloadToFile

Postby RAMESHBABU » Thu Nov 05, 2015 12:07 am

Mr.Enrico,

Thank you very much.

-Ramesh Babu
User avatar
RAMESHBABU
 
Posts: 615
Joined: Fri Oct 21, 2005 5:54 am
Location: Secunderabad (T.S), India

Next

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: cmsoft and 54 guests