i using function file ftp connection,
function getfilefromftp(server, username, password, localfile, remotefile: string; port: word = 21): boolean; var hopen, hconnect: hinternet; good:boolean; begin hopen := internetopen('myagent', internet_open_type_direct, nil, nil, 0); hconnect := internetconnect(hopen, pchar(server), port, pchar(username), pchar(password), internet_service_ftp, internet_flag_passive, 0); := ftpgetfile(hconnect, pchar(remotefile), pchar(localfile), false, 0, ftp_transfer_type_unknown or internet_flag_dont_cache, 0); internetclosehandle(hconnect); result := good; end;
the problem when use server string this:
var server:string; server := 'ftp://192.168.1.1/xdirectory/'; //it cant file server := 'localhost'; //gets file procedure tform1.btn1click(sender: tobject); begin if getfilefromftp(server, '', '', 'upx2.exe', 'upx.exe') begin caption := 'install succesfull'; end else begin caption := 'install not succesfull'; end;
i don't understand why can't ftp server file, if file in folder, or if server ip address used.
it if set server localhost
because server server , not uri. , uri uri , not server. should separate uri's components required function chosen use.
read https://www.google.ru/search?client=opera&q=msdn+ftpgetfile&sourceid=opera , determine expected in variable.
read http://en.wikipedia.org/wiki/uri_scheme#generic_syntax how parse url , extract server name , remote file name different variables.
in string ftp://user:password@192.168.1.1:21/xdirectory/ydirectory/zdirectory/filename
192.168.1.1
"server" - rest different parts , not "server". should extract parts proper separate variables , pass them function documented on msdn.
getfilefromftp(server, '', '', 'upx2.exe', 'upx.exe')
- last 2 parameters here believe wrong - both should fully-qualified names, including paths.
bonus: reformulation
procedure tform1.btn1click(sender: tobject); begin if getfilefromftp(server, '', '', 'upx2.exe', 'upx.exe') begin caption := 'install succesfull'; end else begin caption := 'install not succesfull'; end;
is
procedure tform1.btn1click(sender: tobject); begin caption := 'install ' + ifthen( not getfilefromftp(server, '', '', 'upx2.exe', 'upx.exe'), 'not ') + 'succesfull.'; end;
Comments
Post a Comment