资源简介
基于C#的FTP上传Demo,基于FTP协议,无需服务端应用,只需服务端建立FTP站点,便可实现文件传输,代码简洁清晰,注释详细,方便学习
代码片段和文件信息
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FTPUpload
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private string _fName = ““;
private string _ftpfilepath = ““;
private void button1_Click(object sender EventArgs e)
{
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
_fName = openFileDialog1.FileName;
_ftpfilepath = openFileDialog1.SafeFileName;
lbl_text.Text = openFileDialog1.SafeFileName;
}
}
private void button2_Click(object sender EventArgs e)
{
MessageBox.Show(Ftpfile(_ftpfilepath _fName));
}
///
/// 上传
///
/// 文件名
/// 文件全路径
///
public string Ftpfile(string ftpfilepath string inputfilepath)
{
try
{
string ftphost = “127.0.0.1:21“;//服务端IP
string ftpfullpath = “ftp://“ + ftphost + “/“ + ftpfilepath;
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create(ftpfullpath);
ftp.Credentials = new NetworkCredential(“登录名“ “登录密码“);
ftp.KeepAlive = true;
ftp.UseBinary = true;
ftp.Method = WebRequestMethods.Ftp.UploadFile;
FileStream fs = File.OpenRead(inputfilepath);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer 0 buffer.Length);
fs.Close();
Stream ftpstream = ftp.GetRequestStream();//上传
ftpstream.Write(buffer 0 buffer.Length);
ftpstream.Close();
return “成功“;
}
catch (Exception ex)
{
return ex.Message;
}
}
}
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
..A..H. 38400 2017-12-15 14:32 FTPUpload\.vs\FTPUpload\v14\.suo
文件 189 2017-12-15 14:25 FTPUpload\FTPUpload\App.config
文件 9728 2017-12-15 14:32 FTPUpload\FTPUpload\bin\Debug\FTPUpload.exe
文件 189 2017-12-15 14:25 FTPUpload\FTPUpload\bin\Debug\FTPUpload.exe.config
文件 19968 2017-12-15 14:32 FTPUpload\FTPUpload\bin\Debug\FTPUpload.pdb
文件 22696 2017-12-15 14:30 FTPUpload\FTPUpload\bin\Debug\FTPUpload.vshost.exe
文件 189 2017-12-15 14:25 FTPUpload\FTPUpload\bin\Debug\FTPUpload.vshost.exe.config
文件 490 2017-03-19 05:00 FTPUpload\FTPUpload\bin\Debug\FTPUpload.vshost.exe.manifest
文件 2344 2017-12-15 14:32 FTPUpload\FTPUpload\Form1.cs
文件 3466 2017-12-15 14:29 FTPUpload\FTPUpload\Form1.Designer.cs
文件 6020 2017-12-15 14:29 FTPUpload\FTPUpload\Form1.resx
文件 3916 2017-12-15 14:29 FTPUpload\FTPUpload\FTPUpload.csproj
文件 868 2017-12-15 14:25 FTPUpload\FTPUpload\obj\Debug\DesignTimeResolveAssemblyReferences.cache
文件 7108 2017-12-15 14:25 FTPUpload\FTPUpload\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache
文件 496 2017-12-15 14:30 FTPUpload\FTPUpload\obj\Debug\FTPUpload.csproj.FileListAbsolute.txt
文件 1012 2017-12-15 14:29 FTPUpload\FTPUpload\obj\Debug\FTPUpload.csproj.GenerateResource.Cache
文件 9728 2017-12-15 14:32 FTPUpload\FTPUpload\obj\Debug\FTPUpload.exe
文件 180 2017-12-15 14:29 FTPUpload\FTPUpload\obj\Debug\FTPUpload.Form1.resources
文件 19968 2017-12-15 14:32 FTPUpload\FTPUpload\obj\Debug\FTPUpload.pdb
文件 180 2017-12-15 14:29 FTPUpload\FTPUpload\obj\Debug\FTPUpload.Properties.Resources.resources
文件 0 2017-12-15 14:25 FTPUpload\FTPUpload\obj\Debug\TemporaryGeneratedFile_036C0B5B-1481-4323-8D20-8F5ADCB23D92.cs
文件 0 2017-12-15 14:25 FTPUpload\FTPUpload\obj\Debug\TemporaryGeneratedFile_5937a670-0e60-4077-877b-f7221da3dda1.cs
文件 0 2017-12-15 14:25 FTPUpload\FTPUpload\obj\Debug\TemporaryGeneratedFile_E7A71F73-0F8D-4B9B-B56E-8E70B10BC5D3.cs
文件 521 2017-12-15 14:25 FTPUpload\FTPUpload\Program.cs
文件 1326 2017-12-15 14:25 FTPUpload\FTPUpload\Properties\AssemblyInfo.cs
文件 2831 2017-12-15 14:25 FTPUpload\FTPUpload\Properties\Resources.Designer.cs
文件 5612 2017-12-15 14:25 FTPUpload\FTPUpload\Properties\Resources.resx
文件 1096 2017-12-15 14:25 FTPUpload\FTPUpload\Properties\Settings.Designer.cs
文件 249 2017-12-15 14:25 FTPUpload\FTPUpload\Properties\Settings.settings
文件 994 2017-12-15 14:25 FTPUpload\FTPUpload.sln
............此处省略14个文件信息
- 上一篇:基于Socket的Winform聊天小程序
- 下一篇:.net调用系统cmd指令类
相关资源
- c# socket的ftp上传
- FTP上传、、创建目录、重命名、删除
- C# SFTP上传文件
- C# Sftp上传文件 DiffieHellman.dll org.ment
- C#写的Ftp上传文件、文件夹
- C#WinForm做FTP上传获取文件列表齐全
- winform实现FTP上传、、删除文件
- 疯子ftp上传工具源码传送数据到服务
- [ASP.NET]web实现用FTP上传、文件
- HttpFtp上传, 加载条Demo
- c#实现ftp上传、删除、、新建等功能
- C#通过ftp上传文件至远程服务器
- 竣工资料导入至数据库资料ftp上传
- sftp上传样例代码
- C# FTP上传文件、文件
- FTP上传文件、文件(亲测可用+mvvm+w
- ftp上传
- C# WinFrom 实现的FTP上传
- WEB方式管理FTP上传
评论
共有 条评论