Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Sep : Re: Delete FTP File

www.cryer.info
Managed Newsgroup Archive

Re: Delete FTP File

Subject:Re: Delete FTP File
Posted by:"Craig" (firebirdwebg..@hotmail.com)
Date:Mon, 24 Sep 2007 16:23:51

Funny, you had said that it looked like overkill.. but if you used indy, you
could do this in just a couple of lines of code..


"Anthoni" <nonono@nono.com> wrote in message
news:46f82b8a@newsgroups.borland.com...
> Hi Remy,
>
> I changed the function and added the FTPDeleteFile() and tested and it
seems
> to work.
> It deleted the file from our server. Could you have a quick look at my
code
> and make sure I am doing everything correctly please? Like I said, totally
> new to WinInet and want to make sure dont have memory leaks, etc
>
> <code>
> function TfrmTest.zp_xFTPDelete(const aFile: string; var Err: String):
> Boolean;
> var
>   hNet, hFTP: HINTERNET;
>   bSuccess: Boolean;
>   sRec: TWin32FindData;
>
> begin
>   //
>   Result := False;
>
>   //Prepare WinInet DLL
>   hNet := InternetOpen('myprogram.exe', INTERNET_OPEN_TYPE_PRECONFIG, nil,
> nil, 0);
>   If hNet = Nil then
>   Begin
>     Err := 'Unable to get access to WinInet.Dll';
>     Exit;
>   End;
>
>   //Connect to FTP
>   hFTP := InternetConnect(hNet, PChar('mydomain.org'), 21,
PChar('myuser'),
> PChar('mypass'), INTERNET_SERVICE_FTP, 0, 0);
>   If hFTP = Nil then
>   Begin
>     Err := 'Failed to connect to host';
>     Exit;
>   End;
>
>   //Change to correct directory
>   bSuccess := FtpSetCurrentDirectory(hFTP, '/mydir/');
>   if not bSuccess then
>   begin
>     InternetCloseHandle(hFTP);
>     InternetCloseHandle(hNet);
>     Err := 'Failed to set correct directory';
>     Exit;
>   end;
>
>   If FtpFindFirstFile(hFTP, PChar(aFile), sRec, 0, 0) = nil then
>   Begin
>     InternetCloseHandle(hFTP);
>     InternetCloseHandle(hNet);
>     Err := 'Failed to locate correct file';
>     Exit;
>   End;
>
>   If FtpDeleteFile(hFTP, PChar(aFile)) = False then
>   Begin
>     InternetCloseHandle(hFTP);
>     InternetCloseHandle(hNet);
>     Err := 'Failed to delete file';
>     Exit;
>   End;
>
>   InternetCloseHandle(hFTP);
>   InternetCloseHandle(hNet);
>   Result := True;
> end;
> </code>
>
> Regards
> Anthoni

Replies:

none

In response to:

www.cryer.info
Managed Newsgroup Archive