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

所属分类: 网络编程 / 其它综合 阅读数: 1776
收藏 0 赞 0 分享

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

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

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;

成功:

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

更多精彩内容其他人还在看

软件测试面试如何测试一个杯子

本文主要介绍软件测试面试如何测试一个杯子,这里帮大家整理了详细的面试资料,和面试需要准备的知识点,有兴趣的小伙伴可以参考下
收藏 0 赞 0 分享

软件测试面试如何测试网页的登录页面

本文主要介绍软件测试面试如何测试网页的登录页面,这里整理了相关软件测试的一些基本知识,希望能帮助软件测试的同学
收藏 0 赞 0 分享

常见前端面试题及答案

本文是在GitHub上看到一个大牛总结的前端常见面试题,很多问题问的都很好,很经典、很有代表性。上面没有答案,我就整理了一下,从网上找了一些相关问题的答案
收藏 0 赞 0 分享

PHP和Java的主要区别有哪些?哪个最适合Web开发语言?

Java和PHP都是编程语言,大家知道它们最大的区别就是一个是静态语言一个是动态语言吧。没错,Java是一种静态语言,PHP是一种动态语言。那它们还有哪些区别? 哪个最适合Web开发语言?下面,小编再给大家详细介绍下。
收藏 0 赞 0 分享

玩转markdown 分享几个需要用到的工具

markdown是一个面向写作的语法引擎,markdown的最终目的都是解析成html用于网页浏览,所以它兼容html语法,即你可以在 markdown文档中使用原生的html标签
收藏 0 赞 0 分享

可能是最通俗的一篇介绍markdown的文章

这些日子一直在简书上使用markdown写作,已经渐渐的痴迷于这种简洁纯粹的写作方式了。不过就我逐渐入门markdown的写作过程来看,目前我看到的各种介绍markdown写作方式的文章都还略显极客,对于大多数像我一样没有基础的普通人来说,可能内容上的可接受性没有那么强
收藏 0 赞 0 分享

献给写作者的 Markdown 新手指南

Markdown 是一种「电子邮件」风格的「标记语言」,我们强烈推荐所有写作者学习和掌握该语言。为什么
收藏 0 赞 0 分享

github pull最新代码实现方法

本文主要介绍 github pull最新代码的资料,这里对 github pull最新代码做了详细流程介绍,有需要的小伙伴可以参考下
收藏 0 赞 0 分享

GitHub Eclipse配置使用教程详解

本文主要介绍GitHub Eclipse,这里对Eclipse 使用GitHub的教程,图文并茂详细说明如何操作,有需要的小伙伴可以参考下
收藏 0 赞 0 分享

Git 教程简单入门介绍

本文主要介绍Git 教程简单入门的东西,这里整理了Git 的基础资料和简单命令,有需要的小伙伴可以参考下
收藏 0 赞 0 分享
查看更多