資源簡介
C# SFTP上傳下載文件,此代碼來源于互聯網,本人整理,修改和測試無問題的代碼,共享給大家。
代碼片段和文件信息
using?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“);
????????????????}
????????}?
????}
}
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2014-04-14?10:28??SFTP上傳文件?-?副本\
?????目錄???????????0??2014-04-14?10:31??SFTP上傳文件?-?副本\UploadFile2Sftp\
?????文件???????53248??2013-11-14?15:52??SFTP上傳文件?-?副本\UploadFile2Sftp\DiffieHellman.dll
?????文件????????8778??2014-04-14?10:31??SFTP上傳文件?-?副本\UploadFile2Sftp\Form1.Designer.cs
?????文件????????2309??2014-04-14?10:31??SFTP上傳文件?-?副本\UploadFile2Sftp\Form1.cs
?????文件????????5814??2014-04-14?10:31??SFTP上傳文件?-?副本\UploadFile2Sftp\Form1.resx
?????文件??????184320??2013-11-14?15:52??SFTP上傳文件?-?副本\UploadFile2Sftp\Org.Mentalis.Security.dll
?????文件?????????476??2013-11-14?14:54??SFTP上傳文件?-?副本\UploadFile2Sftp\Program.cs
?????目錄???????????0??2014-04-14?10:28??SFTP上傳文件?-?副本\UploadFile2Sftp\Properties\
?????文件????????1376??2013-11-14?14:54??SFTP上傳文件?-?副本\UploadFile2Sftp\Properties\AssemblyInfo.cs
?????文件????????2880??2013-11-14?14:54??SFTP上傳文件?-?副本\UploadFile2Sftp\Properties\Resources.Designer.cs
?????文件????????5612??2013-11-14?14:54??SFTP上傳文件?-?副本\UploadFile2Sftp\Properties\Resources.resx
?????文件????????1100??2013-11-14?14:54??SFTP上傳文件?-?副本\UploadFile2Sftp\Properties\Settings.Designer.cs
?????文件?????????249??2013-11-14?14:54??SFTP上傳文件?-?副本\UploadFile2Sftp\Properties\Settings.settings
?????文件?????????249??2013-11-14?15:55??SFTP上傳文件?-?副本\UploadFile2Sftp\Properties\vssver2.scc
?????文件????????4714??2014-04-14?10:04??SFTP上傳文件?-?副本\UploadFile2Sftp\SFTPHelper.cs
?????文件??????225280??2013-11-14?14:55??SFTP上傳文件?-?副本\UploadFile2Sftp\Tamir.SharpSSH.dll
?????文件????????4000??2013-11-14?15:55??SFTP上傳文件?-?副本\UploadFile2Sftp\UploadFile2Sftp.csproj
?????文件?????????281??2013-11-14?15:55??SFTP上傳文件?-?副本\UploadFile2Sftp\UploadFile2Sftp.csproj.vspscc
?????目錄???????????0??2014-04-14?10:28??SFTP上傳文件?-?副本\UploadFile2Sftp\bin\
?????目錄???????????0??2014-04-14?10:28??SFTP上傳文件?-?副本\UploadFile2Sftp\bin\Debug\
?????文件???????53248??2013-11-14?15:52??SFTP上傳文件?-?副本\UploadFile2Sftp\bin\Debug\DiffieHellman.dll
?????文件??????184320??2013-11-14?15:52??SFTP上傳文件?-?副本\UploadFile2Sftp\bin\Debug\Org.Mentalis.Security.dll
?????文件??????225280??2013-11-14?14:55??SFTP上傳文件?-?副本\UploadFile2Sftp\bin\Debug\Tamir.SharpSSH.dll
?????文件???????14336??2014-04-14?10:31??SFTP上傳文件?-?副本\UploadFile2Sftp\bin\Debug\UploadFile2Sftp.exe
?????文件???????40448??2014-04-14?10:31??SFTP上傳文件?-?副本\UploadFile2Sftp\bin\Debug\UploadFile2Sftp.pdb
?????文件???????14328??2014-04-14?10:32??SFTP上傳文件?-?副本\UploadFile2Sftp\bin\Debug\UploadFile2Sftp.vshost.exe
?????文件?????????490??2009-06-11?05:14??SFTP上傳文件?-?副本\UploadFile2Sftp\bin\Debug\UploadFile2Sftp.vshost.exe.manifest
?????文件???????33508??2009-06-11?05:22??SFTP上傳文件?-?副本\UploadFile2Sftp\bin\Debug\WindowsLogoffSound.wav
?????文件?????????167??2013-11-14?15:55??SFTP上傳文件?-?副本\UploadFile2Sftp\mssccprj.scc
?????目錄???????????0??2014-04-14?10:28??SFTP上傳文件?-?副本\UploadFile2Sftp\obj\
............此處省略16個文件信息
- 上一篇:用C#寫的個人所得稅計算器
- 下一篇:C#開發大全(基礎卷)源碼-藍松
評論
共有 條評論