Witam,
wprowadzono zmiany na ftp.bossa.pl
Teraz trzeba się logować [anonymous/anonymous].
Okazuje się, że część programów sobie z tym nie radzi np. firefox, mój program również ma problemy z zalogowaniem. Google chrome, total commander nie mają żadnych problemów.
Bardzo proszę o pomoc co robię źle - poniżej kod.
Problem występuje na etapie funkcji InternetConnect.
Niestety nie umiem obsłużyć w delphi InternetGetLastResponseInfo aby dowiedzieć się co jest nie tak :/.
Proszę o jakieś wskazówki. Z góry uprzejmie dziękuję.
procedure TForm1.PobierzPlikFTP(ftpDir, ftpFile, TargetFile: string);
const
READ_BUFFERSIZE = 4096;
strHost = 'ftp.bossa.pl';
port = 21;
strUser = 'anonymous';
strPwd = 'anonymous';
var
hNet, hFTP, hFile : HINTERNET;
buffer : array [0..READ_BUFFERSIZE - 1] of Char;
bufsize, dwBytesRead, fileSize : DWORD;
sRec : TWin32FindData;
LocalFile : file;
bSuccess : Boolean;
begin
dwBytesRead:= 0;
{ Open an internet session }
hNet := InternetOpen('Moj program', INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0);
{ See if connection handle is valid }
if hNet = nil then
begin
ShowMessage('Brak dostępu do: WinInet.Dll');
Exit;
end;
{ Connect to the FTP Server }
hFTP := InternetConnect(hNet, PWideChar(strHost), port, PWideChar(StrUser), PWideChar(strPwd), INTERNET_SERVICE_FTP, 0, 0);
if hFTP = nil then
begin
InternetCloseHandle(hNet);
ShowMessage(Format('Host: "%s" jest niedostępny',[strHost]));
Exit;
end;
{ Change directory }
bSuccess := FtpSetCurrentDirectory(hFTP, PChar(ftpDir));
if not bSuccess then
begin
InternetCloseHandle(hFTP);
InternetCloseHandle(hNet);
ShowMessage(Format('Brak folderu: %s.',[ftpDir]));
Exit;
end;
{ Read size of file }
if FtpFindFirstFile(hFTP, PChar(ftpFile), sRec, 0, 0) <> nil then
begin
//ponizej zly sposob pobierania wielkosci pliku !!!
//fileSize := sRec.nFileSizeLow;
//Label2.Caption:= DateTimeToStr(FileTimeToDateTime(sRec.ftlastWriteTime));
end else
begin
InternetCloseHandle(hFTP);
InternetCloseHandle(hNet);
ShowMessage(Format('Brak pliku: %s',[ftpFile]));
Exit;
end;
{ Open the file }
hFile := FtpOpenFile(hFTP, PChar(ftpFile), GENERIC_READ, FTP_TRANSFER_TYPE_BINARY, 0);
if hFile = nil then
begin
InternetCloseHandle(hFTP);
InternetCloseHandle(hNet);
Exit;
end;
fileSize:= FtpGetFileSize(hFile, @dwBytesRead);
{ Create a new local file }
AssignFile(LocalFile, TargetFile);
{$i-}
Rewrite(LocalFile, 1);
{$i+}
if IOResult <> 0 then
begin
ShowMessage(Format('Nie można utworzyc pliku: %s.',[TargetFile]));
InternetCloseHandle(hFile);
InternetCloseHandle(hFTP);
InternetCloseHandle(hNet);
Exit;
end;
//dwBytesRead := 0;
bufsize := READ_BUFFERSIZE;
while (bufsize > 0) do
begin
Application.ProcessMessages;
if not InternetReadFile(hFile, @buffer, READ_BUFFERSIZE, bufsize) then Break;
if (bufsize > 0) and (bufsize <= READ_BUFFERSIZE) then BlockWrite(LocalFile, buffer, bufsize);
dwBytesRead := dwBytesRead + bufsize;
end;
CloseFile(LocalFile);
InternetCloseHandle(hFile);
InternetCloseHandle(hFTP);
InternetCloseHandle(hNet);
end;