我使用My.Computer.Network.UploadFile方法将文件上传到 FTP 。但我有一些问题。我的问题是上传速度。
例如:我使用一些 FTP 程序(FileZilla),上传速度为 4 Mb/sn。但My.Computer.Network.UploadFile方法是1.20Mb/sn 限制。
为什么这种方法是有限的?我可以提高上传速度吗?
使用此代码朋友并告诉我这是否有用:
using System.Net;
// Get the object used to communicate with the server.
FtpWebRequest request = (FtpWebRequest)FtpWebRequest.Create("ftp://
XXXXXXXXXXXXXXXXXXXXX/" + "C:/XXXXX.zip");
request.Method = WebRequestMethods.Ftp.UploadFile;
request.Credentials = new NetworkCredential("User", "PassWord");
// Copy the contents of the file to the request stream.
Stream ftpStream = request.GetRequestStream();
FileStream file = File.OpenRead("C:/XXXXX.zip");
int length = 1024;
byte[] buffer = new byte[length];
int bytesread = 0;
do
{
bytesread = file.Read(buffer,0,length);
ftpStream.Write(buffer,0,bytesread);
}
while(bytesread != 0);
file.Close();
ftpStream.Close();
MessageBox.Show("Uploaded Successfully");