delphi使用Chilkat 组件和库从SFTP下载文件
程序员文章站
2022-06-15 10:21:57
官网地址:https://www.example-code.com/delphiDll/default.asp 实例代码:(不包括全局解锁) 密码生成器:https://www.cnblogs.com/hhmm99/p/11383027.html 解锁: 成功: ......
官网地址:https://www.example-code.com/delphidll/default.asp
实例代码:(不包括全局解锁) 密码生成器:
uses winapi.windows, winapi.messages, system.sysutils, system.variants, system.classes, vcl.graphics, vcl.controls, vcl.forms, vcl.dialogs, vcl.stdctrls, sftp; ... procedure tform1.button1click(sender: tobject); var sftp: hcksftp; hostname: pwidechar; port: integer; success: boolean; remotefilepath: pwidechar; localfilepath: pwidechar; begin // this example assumes the chilkat api to have been previously unlocked. // see global unlock sample for sample code. sftp := cksftp_create(); // set some timeouts, in milliseconds: cksftp_putconnecttimeoutms(sftp,5000); cksftp_putidletimeoutms(sftp,10000); // connect to the ssh server. // the standard ssh port = 22 // the hostname may be a hostname or ip address. hostname := 'sftp.example.com';// ip port := 22;// 端口 success := cksftp_connect(sftp,hostname,port); if (success <> true) then begin memo1.lines.add(cksftp__lasterrortext(sftp)); exit; end; // authenticate with the ssh server. chilkat sftp supports // both password-based authenication as well as public-key // authentication. this example uses password authenication. success := cksftp_authenticatepw(sftp,'mylogin','mypassword');// 账号密码 if (success <> true) then begin memo1.lines.add(cksftp__lasterrortext(sftp)); exit; end; // after authenticating, the sftp subsystem must be initialized: success := cksftp_initializesftp(sftp); if (success <> true) then begin memo1.lines.add(cksftp__lasterrortext(sftp)); exit; end; // download the file: localfilepath := 'c:/temp/hamlet.xml';// 本地保存路径 remotefilepath := 'subdir1/subdir2/hamlet.xml'; // 服务器文件路径 // the resumedownloadfilebyname method will check // the local file and begin downloading the remote file // at the appropriate point. for example, if the local // file is already 215624 bytes long, it will begin downloading // the remote file at the 215625'th byte -- appending to // the local file. success := cksftp_resumedownloadfilebyname(sftp,remotefilepath,localfilepath); if (success <> true) then begin memo1.lines.add(cksftp__lasterrortext(sftp)); exit; end; memo1.lines.add('success.'); cksftp_dispose(sftp); end; © 2000-2019 chilkat software, inc. all rights reserved.
解锁:
uses winapi.windows, winapi.messages, system.sysutils, system.variants, system.classes, vcl.graphics, vcl.controls, vcl.forms, vcl.dialogs, vcl.stdctrls, global; ... procedure tform1.button1click(sender: tobject); var glob: hckglobal; success: boolean; status: integer; begin // the chilkat api can be unlocked for a fully-functional 30-day trial by passing any // string to the unlockbundle method. a program can unlock once at the start. once unlocked, // all subsequently instantiated objects are created in the unlocked state. // // after licensing chilkat, replace the "anything for 30-day trial" with the purchased unlock code. // to verify the purchased unlock code was recognized, examine the contents of the lasterrortext // property after unlocking. for example: glob := ckglobal_create(); success := ckglobal_unlockbundle(glob,'anything for 30-day trial'); if (success <> true) then begin memo1.lines.add(ckglobal__lasterrortext(glob)); exit; end; status := ckglobal_getunlockstatus(glob); if (status = 2) then begin memo1.lines.add('unlocked using purchased unlock code.'); end else begin memo1.lines.add('unlocked in trial mode.'); end; // the lasterrortext can be examined in the success case to see if it was unlocked in // trial more, or with a purchased unlock code. memo1.lines.add(ckglobal__lasterrortext(glob)); ckglobal_dispose(glob); end;
成功: