谁能给段用vs2005下自带的ftp类下载文件的代码,谢了

tteagle 2006-01-15 01:26:04
vs2005里自带了ftp类,不过没找到示例,兄弟们帮忙给一个,谢了
例如
user:test
pass:test
url:ftp://192.168.0.1
...全文
253 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
tjcloving 2006-04-23
  • 打赏
  • 举报
回复
有上传的代码吗 给一个看看 学习
beijingbeerman 2006-01-16
  • 打赏
  • 举报
回复
mark
qqdown 2006-01-15
  • 打赏
  • 举报
回复
这个是微软自己带的一个例子,挺简单的,上传和这个也大致差不多,把里面的api自己看一下基本上也能看得懂。

using System;
using System.Text;
using System.IO;
using System.Net;

namespace FTPSample
{
class SimpleFTPClient
{
public FtpStatusCode Download(string destinationFile, Uri downloadUri)
{
try
{
// Check if the URI is and FTP site
if (downloadUri.Scheme != Uri.UriSchemeFtp)
{
throw new ArgumentException("URI is not an FTp site");
}

// Set up the request
FtpWebRequest ftpRequest = (FtpWebRequest)WebRequest.Create(downloadUri);

// use the provided credentials
if (this._isAnonymousUser == false)
{
ftpRequest.Credentials = new NetworkCredential(this._userName, this._password);
}

// Download a file. Look at the other methods to see all of the potential FTP features
ftpRequest.Method = WebRequestMethods.Ftp.DownloadFile;

// get the response object
FtpWebResponse ftpResponse = (FtpWebResponse)ftpRequest.GetResponse();


Stream stream = null;
StreamReader reader = null;
StreamWriter writer = null;

// get the file as a stream from the response object and write it as
// a file stream to the local PC
try
{
stream = ftpResponse.GetResponseStream();
reader = new StreamReader(stream, Encoding.UTF8);

writer = new StreamWriter(destinationFile, false);
writer.Write(reader.ReadToEnd());

return ftpResponse.StatusCode;
}
finally
{
// Allways close all streams
stream.Close();
reader.Close();
writer.Close();
}
}
catch (Exception ex)
{
throw ex;
}
}

public string UserName
{
get { return this._userName; }
set { this._userName = value; }
}
public string Password
{
get { return this._password; }
set { this._password = value; }
}
public bool IsAnonymousUser
{
get { return this._isAnonymousUser; }
set { this._isAnonymousUser = value; }
}

private string _userName;
private string _password;
private bool _isAnonymousUser;
}
}
tteagle 2006-01-15
  • 打赏
  • 举报
回复
怎么没人理我,分不够?
tteagle 2006-01-15
  • 打赏
  • 举报
回复
还有吗?

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧