您的位置:首页 > 编程语言 > C#

c# sftp 库 Chilkat

2016-04-23 16:15 941 查看
http://www.chilkatsoft.com/mono.asp

Sample Script for Install/Testing on 64-bit Linux

Note: The download URL is for v9.5.0.54. At the time of this writing, it was the latest version of Chilkat.

#!/bin/bash -ef

curl "http://www.chilkatsoft.com/download/9.5.0.54/chilkatMono-9.5.0.zip" -o "chilkatMono-9.5.0.zip"
unzip chilkatMono-9.5.0.zip
cd chilkatMono-9.5.0
sn -k chilkat.snk
mcs -keyfile:chilkat.snk -target:library -out:chilkatMono.dll chilkatCs/*.cs
cp nativeDll/linux/x64/libchilkatMono-9_5_0.so .
mcs -lib:. -r:chilkatMono.dll chilkatTest.cs
mono chilkatTest.exe
cd ..

Sample Script for Install/Testing on MAC OS X

Note: The download URL is for v9.5.0.54. At the time of this writing, it was the latest version of Chilkat.

#!/bin/bash -ef

curl "http://www.chilkatsoft.com/download/9.5.0.54/chilkatMono-9.5.0.zip" -o "chilkatMono-9.5.0.zip"
unzip chilkatMono-9.5.0.zip
cd chilkatMono-9.5.0
sn -k chilkat.snk
mcs -keyfile:chilkat.snk -target:library -out:chilkatMono.dll chilkatCs/*.cs
cp nativeDll/mac/libchilkatMono-9_5_0.dylib .
mcs -lib:. -r:chilkatMono.dll chilkatTest.cs
mono chilkatTest.exe
cd ..


使用方法:
http://www.example-code.com/csharp/scp_upload_file.asp
//  Important: It is helpful to send the contents of the
//  ssh.LastErrorText property when requesting support.

Chilkat.Ssh ssh = new Chilkat.Ssh();

//  Any string automatically begins a fully-functional 30-day trial.
bool success = ssh.UnlockComponent("30-day trial");
if (success != true) {
Console.WriteLine(ssh.LastErrorText);
return;
}

//  Connect to an SSH server:
string hostname;
int port;

//  Hostname may be an IP address or hostname:
hostname = "www.some-ssh-server.com";
port = 22;

success = ssh.Connect(hostname,port);
if (success != true) {
Console.WriteLine(ssh.LastErrorText);
return;
}

//  Wait a max of 5 seconds when reading responses..
ssh.IdleTimeoutMs = 5000;

//  Authenticate using login/password:
success = ssh.AuthenticatePw("myLogin","myPassword");
if (success != true) {
Console.WriteLine(ssh.LastErrorText);
return;
}

//  Once the SSH object is connected and authenticated, we use it
//  as the underlying transport in our SCP object.
Chilkat.Scp scp = new Chilkat.Scp();

success = scp.UseSsh(ssh);
if (success != true) {
Console.WriteLine(scp.LastErrorText);
return;
}

string remotePath = "test.txt";
string localPath = "/home/bob/test.txt";
success = scp.UploadFile(localPath,remotePath);
if (success != true) {
Console.WriteLine(scp.LastErrorText);
return;
}

Console.WriteLine("SCP upload file success.");

//  Disconnect
ssh.Disconnect();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: