FtpWebRequest只能上传12,484,608 字节的问题

mygis 2008-06-02 09:56:51
用.net 2.0的FtpWebRequest类来上传文件,ftp server是serv-u 6.0版,传输小于12,484,608 字节的文件是成功的(上传正确),可是大于这个大小的文件就断了,错误提示:..."放弃了一个已建立的连接",意思就是ftp连接关闭了。不知道这个问题在哪里,怎么解决,请帮我。代码如下:

private void Upload(string filename)
{
FileInfo fileInf = new FileInfo(filename);
string uri = "ftp://" + ftpServerIP + "/" + fileInf.Name;
FtpWebRequest reqFTP;

// Create FtpWebRequest object from the Uri provided
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + fileInf.Name));

// Provide the WebPermission Credintials
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);

// By default KeepAlive is true, where the control connection is not closed
// after a command is executed.
reqFTP.KeepAlive = false;
// reqFTP.KeepAlive = true;

// Specify the command to be executed.
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;

// Specify the data transfer type.
reqFTP.UseBinary = true;

// Notify the server about the size of the uploaded file
reqFTP.ContentLength = fileInf.Length;

// The buffer size is set to 2kb
// int buffLength = 2048;
int buffLength = 1024;
byte[] buff = new byte[buffLength];
int contentLen;

// Opens a file stream (System.IO.FileStream) to read the file to be uploaded
FileStream fs = fileInf.OpenRead();

try
{
// Stream to which the file to be upload is written
Stream strm = reqFTP.GetRequestStream();

// Read from the file stream 2kb at a time
contentLen = fs.Read(buff, 0, buffLength);

// Till Stream content ends
while (contentLen != 0)
// int count = 0;
// while ((count = strm.Read(buff, 0, 1024)) > 0)
{
// Write Content from the file stream to the FTP Upload Stream
strm.Write(buff, 0, contentLen);
// strm.Write(buff, 0, count);
contentLen = fs.Read(buff, 0, buffLength);
}

// Close the file stream and the Request Stream
strm.Close();
fs.Close();
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, "Upload Error");
}
}
...全文
87 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
shmilyweng 2011-02-16
  • 打赏
  • 举报
回复
敢问楼上具体的设置方法
周公 2008-06-03
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 Tll_W 的回复:]
估计是配置中限制上传大小了吧?
[/Quote]
有可能是FTP服务器限制了上传的单个文件大小。
Tll_W 2008-06-03
  • 打赏
  • 举报
回复
估计是配置中限制上传大小了吧?
changjiangzhibin 2008-06-03
  • 打赏
  • 举报
回复
Ftp应该是不会的,没细看,跟踪调试一下
mygis 2008-06-03
  • 打赏
  • 举报
回复
解决了,还是ftp的设置问题。
zdjray 2008-06-02
  • 打赏
  • 举报
回复
关注,诡异的问题

110,499

社区成员

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

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

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