Article View: borland.public.cppbuilder.internet.socket
Article #372Re: Stop the indy Get() function
From: Remy Lebeau (TeamB)
Date: Thu, 27 Mar 2008 09:41
Date: Thu, 27 Mar 2008 09:41
49 lines
2411 bytes
2411 bytes
"bar" <shaikakbar250281@yahoo.co.in> wrote in message
news:47eb5fc5@newsgroups.borland.com...
> Even when the file is not present at the server or if any
> kind of exception raises. Still the file is creating with 0 bytes.
That is because you are not deleting the file if the download fails.
> How to avoid this, i mean create the file only if the download success.
You have to create the file first before starting the download, or else you
won't have anything to download into (unless you download to memory first,
and then save it to file afterwards). If the download fails, simply delete
the file, for example:
void TfrmMain::DownloadFile(String URL)
{
ErrFile = "";
try
{
String FileName = "SomeFileName.bmp";
try
{
std::auto_ptr<TFileStream> strm(new TFileStream(FileName,
fmCreate));
HTTP->Request->Pragma = "no-cache";
HTTP->HandleRedirects = true;
HTTP->ReadTimeout = 15000;
HTTP->Get(URL, strm.get());
}
catch(const Exception &E)
{
if( !E.InheritsFrom(__classid(EFCreateError)) )
DeleteFile(FileName);
throw;
}
}
catch(const Exception &E)
{
ErrFile = E.Message;
}
}
Gambit
Technical Details
Message-ID:
<47eb6c6b@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!news.isoc.lu!newsgroups.borland.com!not-for-mailReferences:
<47ea86a8@newsgroups.borland.com> <47ea8cb8$1@newsgroups.borland.com> <47eb5fc5@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,8732be4783ae43b6 X-Google-Attributes: gid11508e,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.internet.socket References: <47ea86a8@newsgroups.borland.com> <47ea8cb8$1@newsgroups.borland.com> <47eb5fc5@newsgroups.borland.com> Subject: Re: Stop the indy Get() function Date: Thu, 27 Mar 2008 02:41:31 -0700 Lines: 51 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-RFC2646: Format=Flowed; Response X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 NNTP-Posting-Host: 76.89.173.41 Message-ID: <47eb6c6b@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1206611051 76.89.173.41 (27 Mar 2008 02:44:11 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!news.isoc.lu!newsgroups.borland.com!not-for-mail