我用c#写了一段从ftp服务器下载文件的代码,下载3g以下的文件一切正常,当下载3g以上文件时,本机上复制到了ftp服务器上的文件 但是没有下载 文件大小为0kb。
然后我用ftp软件去下载 无论文件大小是多少都能够正常下载。有人说时ftp服务器防火墙的问题,有人说是ie有限制不能下载大文件,请有知道的能帮助看一下怎么解决或者设置吗?
然后我用ftp软件去下载 无论文件大小是多少都能够正常下载。有人说时ftp服务器防火墙的问题,有人说是ie有限制不能下载大文件,请有知道的能帮助看一下怎么解决或者设置吗?
解决方案 »
- C# 使用DllImport()时,出现 请输入class delegate enum interface
- 奇怪,程序在debug调试下速度很快,生成exe后反而卡住不动了.....
- 请问在c#中 Main中 这个是什么意思?
- 大家,都来看一下,瞧一瞧,这个用哪种方法做更好呢?谢谢!
- 问个c#语法问题,就是函数前加上[...]的问题。
- 如何判断当前哪个TabPage被选中
- 还是DataGrid问题
- [初级问题]关于两个form之间共享一个DataSet的问题
- 知道为什么很多C#的chm格式的电子书打不开吗
- 请问一个关于连接ACCESS数据库问题?
- 用c#做应用软件 需要知道掌握什么技术
- #define c# 预处理命令与编译的问题
服务器操作系统2003,FTP用的是FileZilla。
代码如下,窗体上放两个Button和一个Label控件。 public partial class FtpForm : Form
{
WebClient _ftpClient; public FtpForm()
{
InitializeComponent(); _ftpClient = new FtpClient();
_ftpClient.DownloadProgressChanged +=
new DownloadProgressChangedEventHandler(_ftpClient_DownloadProgressChanged);
_ftpClient.DownloadFileCompleted +=
new AsyncCompletedEventHandler(_ftpClient_DownloadFileCompleted);
} void _ftpClient_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{ if (e.Error != null)
MessageBox.Show("Error downloading file: " + e.Error.Message, "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
else
if (e.Cancelled)
{
MessageBox.Show("Download progress has been cancelled.", "Warning",
MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
else
{
var dr = MessageBox.Show("Download completed, open it now?", "Completed",
MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
if (dr == System.Windows.Forms.DialogResult.Yes)
System.Diagnostics.Process.Start(((DownloadState)e.UserState).FileName);
}
} void _ftpClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
// 貌似不能获得文件的长度,所以进度是没有意义的,只能显示已经下载的字节数。
DownloadState state = (DownloadState)e.UserState;
double speed;
speed = e.BytesReceived / state.Timer.Elapsed.TotalSeconds / 1024.0;
label1.Text = e.BytesReceived.ToString("N0") + " (" + speed.ToString("N2") + "KB/s)";
} private void button1_Click(object sender, EventArgs e)
{
if (!_ftpClient.IsBusy)
{
Uri uri = new Uri("ftp://username:passsword@host/path/filename.ext");
StartDownload(uri, "c:\\temp\\download.mkv");
}
} private void StartDownload(Uri url, string saveAs)
{
if (!_ftpClient.IsBusy)
{
DownloadState state = new DownloadState();
state.FileName = saveAs;
state.Timer.Start();
_ftpClient.DownloadFileAsync(url, saveAs, state);
}
else
MessageBox.Show("Downloading file now.");
} protected override void OnFormClosed(FormClosedEventArgs e)
{
base.OnFormClosed(e); _ftpClient.Dispose();
} private void button2_Click(object sender, EventArgs e)
{
if (_ftpClient.IsBusy)
_ftpClient.CancelAsync();
} class DownloadState
{
public DownloadState()
{
_timer = new Stopwatch();
} private Stopwatch _timer; public Stopwatch Timer
{
get { return _timer; }
} private string _fileName; public string FileName
{
get { return _fileName; }
set { _fileName = value; }
} } class FtpClient : WebClient
{
public FtpClient()
{
} protected override WebRequest GetWebRequest(Uri address)
{
FtpWebRequest request = (FtpWebRequest)base.GetWebRequest(address);
// 由于是内网,不使用PASV模式。
request.UsePassive = false;
return request;
} }
}