服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

PHP教程|ASP.NET教程|Java教程|ASP教程|编程技术|正则表达式|C/C++|IOS|C#|Swift|Android|VB|R语言|JavaScript|易语言|vb.net|

服务器之家 - 编程语言 - 编程技术 - delphi使用Chilkat 组件和库从SFTP下载文件的方法

delphi使用Chilkat 组件和库从SFTP下载文件的方法

2020-09-22 15:59黄浩# 编程技术

这篇文章主要介绍了delphi使用Chilkat 组件和库从SFTP下载文件的方法,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下

官网地址:https://www.example-code.com/delphiDll/default.asp

实例代码:(不包括全局解锁) 密码生成器:https://www.cnblogs.com/hhmm99/p/11383027.html

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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.

解锁:

delphi使用Chilkat 组件和库从SFTP下载文件的方法

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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;

成功:

delphi使用Chilkat 组件和库从SFTP下载文件的方法

总结

以上所述是小编给大家介绍的delphi使用Chilkat 组件从SFTP下载文件的方法,希望对大家有所帮助,如果大家有任何疑问欢迎给我留言,小编会及时回复大家的!

原文链接:https://www.cnblogs.com/hhmm99/archive/2019/08/20/11382981.html

延伸 · 阅读

精彩推荐
  • 编程技术让开发效率倍增的 VS Code 插件

    让开发效率倍增的 VS Code 插件

    今天来分享一些提升开发效率的实用 VS Code 插件!Better Comments 扩展可以帮助我们在代码中创建更人性化的注释,有不同形式和颜色的注释供我们选择。 ...

    前端充电宝7132022-04-21
  • 编程技术用户态 Tcpdump 如何实现抓到内核网络包的?

    用户态 Tcpdump 如何实现抓到内核网络包的?

    在网络包的发送和接收过程中,绝大部分的工作都是在内核态完成的。那么问题来了,我们常用的运行在用户态的程序 tcpdump 是那如何实现抓到内核态的包...

    开发内功修炼11612021-09-08
  • 编程技术Delphi - Indy idMessage和idSMTP实现邮件的发送

    Delphi - Indy idMessage和idSMTP实现邮件的发送

    这篇文章主要介绍了Delphi - Indy idMessage和idSMTP实现邮件的发送,本文通过实例代码给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友可以参考下...

    JJ_JeremyWu6592020-09-22
  • 编程技术从Context源码实现谈React性能优化

    从Context源码实现谈React性能优化

    这篇文章主要介绍Context的实现原理,源码层面掌握React组件的render时机,从而写出高性能的React组件,源码层面了解shouldComponentUpdate、React.memo、PureComponen...

    魔术师卡颂5312020-12-20
  • 编程技术2021年值得关注的React PDF 库

    2021年值得关注的React PDF 库

    今天,许多网络应用程序为其用户提供内置的PDF浏览选项。然而,选择一个并不容易,因为它们的功能远远超过显示PDF。在这篇文章中,我将评估5个React的...

    TianTianUp5222021-06-21
  • 编程技术真正聪明的程序员,总有办法不加班

    真正聪明的程序员,总有办法不加班

    工作效率提升了,就可以少加班了,聪明的程序员,总会有一堆可以提升编码效率的工具?当一种工具满足不了工作需求,就去探索新的,今天纬小创就给...

    今日头条12482021-03-04
  • 编程技术AIOps,SRE工程师手中的利器

    AIOps,SRE工程师手中的利器

    AIOps开始成为一种极为重要的站点可靠性工程工具。它能够高效吸纳观察数据、参与数据以及来自第三方工具的数据,判断系统运行状态并保证其处于最佳...

    至顶网5962021-03-08
  • 编程技术简单、好懂的Svelte实现原理

    简单、好懂的Svelte实现原理

    本文会围绕一张流程图和两个Demo讲解,正确的食用方式是用电脑打开本文,跟着流程图、Demo一边看、一边敲、一边学...

    魔术师卡颂4822021-11-10