博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
delphi使用Chilkat 组件和库从SFTP下载文件
阅读量:4550 次
发布时间:2019-06-08

本文共 3593 字,大约阅读时间需要 11 分钟。

官网地址:

实例代码:(不包括全局解锁)  密码生成器:

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);varsftp: 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';// ipport := 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);varglob: 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.');  endelse  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;

 

成功:

 

转载于:https://www.cnblogs.com/hhmm99/p/11382981.html

你可能感兴趣的文章
ASP.NET Core 2.1 : 十五.图解路由(2.1 or earler)
查看>>
服务器返回状态码说明
查看>>
GitHub for Windows提交失败“failed to sync this branch”
查看>>
linux 安装 git
查看>>
Margin
查看>>
完成登录与注册页面的前端
查看>>
centos 源码安装php7
查看>>
Log4j详细教程
查看>>
UVa-1368-DNA序列
查看>>
ConfigParser模块
查看>>
如何开发优质的 Flutter App:Flutter App 软件测试指南
查看>>
决胜Flutter 第一章 熟悉战场
查看>>
如何开发优质的 Flutter App:Flutter App 软件调试指南
查看>>
决胜经典算法之冒泡排序
查看>>
决胜经典算法之选择排序
查看>>
11、求二进制中1的个数
查看>>
【nodejs】让nodejs像后端mvc框架(asp.net mvc)一样处理请求--请求处理结果适配篇(7/8)...
查看>>
CodeForces 731A Night at the Museum
查看>>
MySQL 删除数据库
查看>>
JavaScript 字符串(String) 对象
查看>>