Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Nov : wininet: Replace existing file
| Subject: | wininet: Replace existing file |
| Posted by: | "Joe H" (joedot..@att.net) |
| Date: | 5 Nov 2007 06:13:39 |
I'm using wininet functions to update a current versions list on my web
site so that my software can implement a "check for upgrades" function.
Unfortunately, this only seems to work when the file is not already on
the site. In other words it won't let me replace the existing file. I
tried to see if there was a way to delete the file using some winInet
http function but I could not see a way to do it. I was told several
years ago by my Internet host (earthlink) that ftp access cannot access
the main web site files but only an ftp folder on the site. Since I can
do all of that using wsftp, I don't believe that's true but I'm not
sure. If anyone can see what's wrong with the code below that won't let
me overwrite an existing file (but does not give show any errors) or
knows how to first delete the file so that the upload will work, I'd
very much appreciate it. Note: it never gives me an error code but just
goes through the motions like it's going to work but when I check the
site, the new files are not there. Surely there must be a way to delete
a file using http.
hsession := InternetOpen(pchar(application.exenam),
INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
if assigned(hsession) then
try
hconnect := InternetConnect(
hSession,
pchar(webserver),
INTERNET_DEFAULT_HTTP_PORT,
pchar(webusername),
pchar(webPassword),
INTERNET_SERVICE_HTTP, 0,0);
if assigned(hconnect) then
try
// This inner block is actually a separate routine
// in my actual code so I can send multiple files
// during a single connect.
fillchar(bufferin, sizeof(bufferin),0);
bufferin.dwstructruesize := siszeof(bufferin);
filein := fileOpen(Thefile,fmOpenRead);
if FileIn <> InvalidFileHandle then
try
total := GetFileSize(FileIn,Nil);
bufferIn.dwBufferTotal := total;
hRequest := httpOpenRequest(hconnect,'PUT',pchar(FileOut),
nil,nil,nil,0,0);
if assigned(hRequest) then
try
sum := 0;
if httpSendRequestEX(hRequest,@bufferin,nil,HSR_INITIATE,0)' then
repeat
bytesRead := FileRead(fileIn,buffer, sizeof(buffer));
if BytesRead > 0 then
if not InternetWriteFile(hRequest, @buffer, BytesRead,
BytesSent) then break;
inc(sum,bytesRead);
if assigned(progress) then
progress(barefn, sum, total, abort);
until abort or (bytesread < sizeof(buffer));
finally
httpEndRequest(hRequest,nil,0,0);
end;
finally
fileClose(FileIn);
end;
finally
InternectCloseHandle(hconnect);
end;
finally
InternetCloseHandle(hSession);
end;
-