找传奇、传世资源到传世资源站!

sftp上传下载样例代码

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

from clipboardusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace UploadFile2Sftp{ public partial class Form1 : Form { SFTPHelper SFTP; public Form1() { InitializeComponent(); } private void btnConnect_Click(object sender, EventArgs e) { SFTP = new SFTPHelper(txtServer.Text, txtUser.Text, txtPwd.Text); if (!SFTP.Connect()) { MessageBox.Show("connect fail"); } else { MessageBox.Show("connect ok"); } } private void btnClose_Click(object sender, EventArgs e) { } private void btnSelFile_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Multiselect = false; if (ofd.ShowDialog() == DialogResult.OK) { txtFile.Text = ofd.FileName; } } private void btnUpload_Click(object sender, EventArgs e) { if (txtFile.Text.Trim()!=string.Empty && SFTP.Connected) { if (SFTP.Put(txtFile.Text, "sounds","888_3.txt")) { MessageBox.Show("upload ok"); } else { MessageBox.Show("upload fail"); } } } private void btnClose_Click_1(object sender, EventArgs e) { if (SFTP.Connected) { SFTP.Disconnect(); } } private void button1_Click(object sender, EventArgs e) { string DownloadFileName = "3d1f5463_P4HGK426_3.wav";//这是服务器上音频文件的名称 if (SFTP.Get("sounds/888_3.txt", @"C:\999_3.txt")) { MessageBox.Show("download ok"); } else { MessageBox.Show("download fail"); } } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复