这里我在ftp服务器上传最多10 GB的文件,但它在1 gb数据上传后停止了这个过程。下面是我上传1 GB数据的代码。
try
{
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)WebRequest.Create("ftp");
request.Method = WebRequestMethods.Ftp.UploadFile;
// This example assumes the FTP site uses anonymous logon.
request.Credentials = new NetworkCredential("UserName","Password");
// Copy the contents of the file to the request stream.
using (Stream sourceStream = File.OpenRead("D:/data.zip"))
using (Stream reqStrm = request.GetRequestStream())
{
int i = 0;
byte[] buffer = new byte[1024 * 1024]; //1 MB buffer
int count = 0;
do
{
i = i + 1;
count = sourceStream.Read(buffer, 0, buffer.Length);
if (count > 0)
{
Console.WriteLine(buffer.Length + " "+i);
reqStrm.Write(buffer, 0, count);
}
}
while (count > 0);
}
FtpWebResponse response = (FtpWebResponse)request.GetResponse();
response.Close();
}
catch (WebException e)
{
String status = ((FtpWebResponse)e.Response).StatusDescription;
}
我们可以用这种方式上传10 GB的数据吗?