本文介紹了C#:FTP 上傳緩沖區大小的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
限時送ChatGPT賬號..
我已經使用了 FTP 上傳功能,但是我想問一些問題這是緩沖區大小,我將其設置為 20KB 這是什么意思,如果我增加/減少它會有所不同嗎?
I have go that FTP Upload function , but there is something that i want to ask about It is the Buffer size , i set it to 20KB what does it mean and would it make difference if i increased/decreased it ?
private void Upload(string filename)
{
FileInfo fi = new FileInfo(filename);
FtpWebRequest ftp = (FtpWebRequest)FtpWebRequest.Create("ftp://" + textBox1.Text + "/" + Path.GetFileName(filename));
ftp.Credentials = new NetworkCredential(textBox2.Text, textBox3.Text);
ftp.Method = WebRequestMethods.Ftp.UploadFile;
ftp.UseBinary = true;
ftp.KeepAlive = false;
ftp.ContentLength = fi.Length;
// The buffer size is set to 20kb
int buffLength = 20480;
byte[] buff = new byte[buffLength];
int contentLen;
//int totalReadBytesCount = 0;
FileStream fs = fi.OpenRead();
try
{
// Stream to which the file to be upload is written
Stream strm = ftp.GetRequestStream();
// Read from the file stream 2kb at a time
contentLen = fs.Read(buff, 0, buffLength);
// Till Stream content ends
while (contentLen != 0)
{
// Write Content from the file stream to the
// FTP Upload Stream
strm.Write(buff, 0, contentLen);
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");
}
}
推薦答案
對于桌面系統上的 FTP,大約 256Kb 的塊大小在我們的測試中產生了最佳性能.較小的緩沖區大小會顯著降低傳輸速度.我建議您自己進行一些測量,但是 20Kb 對于緩沖區來說絕對太少了.
For FTP on desktop systems block size of about 256Kb produced the best performance in our tests. Small buffer sizes decrease speed of transfer significantly. I recommend that you do some measurements yourself, but 20Kb is definitely too little for a buffer.
這篇關于C#:FTP 上傳緩沖區大小的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!