资源简介
C#版本的SCP上传和下载(基于Renci.SshNet),Vs2008工程,完整源代码,有进度条提示。

代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Renci.SshNet;
using Renci.SshNet.Common;
namespace ScpFileTransfer
{
public partial class Form1 : Form
{
private static ScpClient scpClient=null;
public Form1()
{
InitializeComponent();
}
private void btnDownload_Click(object sender EventArgs e)
{
if (scpClient != null)
{
if (scpClient.IsConnected)
{
scpClient.Disconnect();
}
scpClient.Dispose();
}
string scpHostIP = textHostIp.Text;
string scpUSER = textUsr.Text;
string scpPwd = textPwd.Text;
int scpPORT = 22;
string remotePath = textServerFile.Text;
string localPath = textLocalFile.Text;
try{
//注意,需要加上try catch语句
scpClient = new ScpClient(scpHostIP scpPORT scpUSER scpPwd);
scpClient.BufferSize = 1024;
System.IO.FileInfo fi = new System.IO.FileInfo(localPath);
scpClient.Connect();
scpClient.Downloading += scpDownloadInfoShow;//这里是直接使用+号,不能用new来添加.用new方式会报错
initProgressbar();
setBtnStatus(false);
scpClient.Download(remotePath fi);
}
catch(Exception e1){
setBtnStatus(true);
MessageBox.Show(e1.Message);
}
}
//定义委托方法
void scpDownloadInfoShow(object sender ScpDownloadEventArgs e)
{
progressBar1.Value = (int)(100 * (e.Downloaded) / (e.Size));
if (e.Downloaded >= e.Size)
{
setBtnStatus(true);
MessageBox.Show(“下载完成“);
}
}
private void setBtnStatus(bool st)
{
btnDownload.Enabled = st;
btnUpload.Enabled = st;
}
private void initProgressbar()
{
progressBar1.Maximum = 100;//设置最大长度值
progressBar1.Value = 0;//设置当前值
progressBar1.Step = 1;//设置没次增长多少
progressBar1.Visible = true;
}
private void btnUpload_Click(object sender EventArgs e)
{
if (scpClient != null)
{
if (scpClient.IsConnected)
{
scpClient.Disconnect();
}
scpClient.Dispose();
}
string scpHostIP = textHostIp.Text;
string scpUSER = textUsr.Text;
string scpPwd = textPwd.Text;
int scpPORT = 22;
string remotePath = textServerFile.Text;
s
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 470016 2019-03-02 16:45 ScpFileTransfer\ScpFileTransfer\bin\Debug\Renci.SshNet.dll
文件 12288 2019-03-04 10:21 ScpFileTransfer\ScpFileTransfer\bin\Debug\ScpFileTransfer.exe
文件 28160 2019-03-04 10:21 ScpFileTransfer\ScpFileTransfer\bin\Debug\ScpFileTransfer.pdb
文件 14328 2019-03-04 10:23 ScpFileTransfer\ScpFileTransfer\bin\Debug\ScpFileTransfer.vshost.exe
文件 490 2009-06-11 05:14 ScpFileTransfer\ScpFileTransfer\bin\Debug\ScpFileTransfer.vshost.exe.manifest
文件 470016 2019-03-02 16:45 ScpFileTransfer\ScpFileTransfer\dll\Renci.SshNet.dll
文件 167266 2019-03-02 16:49 ScpFileTransfer\ScpFileTransfer\dll\Renci.SshNet.rar
文件 4256 2019-03-04 10:21 ScpFileTransfer\ScpFileTransfer\Form1.cs
文件 8568 2019-03-04 10:14 ScpFileTransfer\ScpFileTransfer\Form1.Designer.cs
文件 5814 2019-03-04 10:14 ScpFileTransfer\ScpFileTransfer\Form1.resx
文件 4569 2019-03-04 09:05 ScpFileTransfer\ScpFileTransfer\obj\Debug\ResolveAssemblyReference.cache
文件 730 2019-03-04 10:23 ScpFileTransfer\ScpFileTransfer\obj\Debug\ScpFileTransfer.csproj.FileListAbsolute.txt
文件 847 2019-03-04 10:17 ScpFileTransfer\ScpFileTransfer\obj\Debug\ScpFileTransfer.csproj.GenerateResource.Cache
文件 12288 2019-03-04 10:21 ScpFileTransfer\ScpFileTransfer\obj\Debug\ScpFileTransfer.exe
文件 180 2019-03-04 10:17 ScpFileTransfer\ScpFileTransfer\obj\Debug\ScpFileTransfer.Form1.resources
文件 28160 2019-03-04 10:21 ScpFileTransfer\ScpFileTransfer\obj\Debug\ScpFileTransfer.pdb
文件 180 2019-03-04 09:05 ScpFileTransfer\ScpFileTransfer\obj\Debug\ScpFileTransfer.Properties.Resources.resources
文件 496 2019-03-04 08:51 ScpFileTransfer\ScpFileTransfer\Program.cs
文件 1380 2019-03-04 08:51 ScpFileTransfer\ScpFileTransfer\Properties\AssemblyInfo.cs
文件 2880 2019-03-04 08:51 ScpFileTransfer\ScpFileTransfer\Properties\Resources.Designer.cs
文件 5612 2019-03-04 08:51 ScpFileTransfer\ScpFileTransfer\Properties\Resources.resx
文件 1100 2019-03-04 08:51 ScpFileTransfer\ScpFileTransfer\Properties\Settings.Designer.cs
文件 249 2019-03-04 08:51 ScpFileTransfer\ScpFileTransfer\Properties\Settings.settings
文件 3994 2019-03-04 09:05 ScpFileTransfer\ScpFileTransfer\ScpFileTransfer.csproj
文件 935 2019-03-04 08:51 ScpFileTransfer\ScpFileTransfer.sln
..A..H. 17920 2019-03-04 10:36 ScpFileTransfer\ScpFileTransfer.suo
目录 0 2019-03-04 10:15 ScpFileTransfer\ScpFileTransfer\obj\Debug\Refactor
目录 0 2019-03-04 08:51 ScpFileTransfer\ScpFileTransfer\obj\Debug\TempPE
目录 0 2019-03-04 09:06 ScpFileTransfer\ScpFileTransfer\bin\Debug
目录 0 2019-03-04 10:21 ScpFileTransfer\ScpFileTransfer\obj\Debug
............此处省略9个文件信息
相关资源
- C# TIP文件生成和拆解
- C#解析HL7消息的库135797
- C# OCR数字识别实例,采用TessnetOcr,对
- 考试管理系统 - C#源码
- asp.net C#购物车源代码
- C#实时网络流量监听源码
- C#百度地图源码
- Visual C#.2010从入门到精通配套源程序
- C# 软件版本更新
- C#屏幕软键盘源码,可以自己定制界面
- 智慧城市 智能家居 C# 源代码
- c#获取mobile手机的IMEI和IMSI
- C#实现简单QQ聊天程序
- 操作系统 模拟的 欢迎下载 C#版
- C#写的计算机性能监控程序
- 用C#实现邮件发送,有点类似于outlo
- MVC model层代码生成器 C#
- c#小型图书销售系统
- C# Socket Server Client 通讯应用 完整的服
- c# winform 自动登录 百度账户 源代码
- C#编写的16进制计算器
- C#TCP通信协议
- C# 数据表(Dataset)操作 合并 查询一
- C#语音识别系统speechsdk51,SpeechSDK51L
- 数据库备份还原工具1.0 C# 源码
-
[免费]xm
lDocument 节点遍历C# - EQ2008LEDc#开发实例
- DirectX.Capturec# winform 操作摄像头录像附
- c# 实现的最大最小距离方法对鸢尾花
- C#版保龄球记分代码
评论
共有 条评论