gpt4 book ai didi

C# : FTP upload buffer size

转载 作者:太空狗 更新时间:2023-10-30 00:26:29 27 4
gpt4 key购买 nike

FTP 上传功能我已经去了,但是有件事想问一下这是缓冲区大小,我将它设置为 20KB,这是什么意思,如果我增加/减少它会有什么不同吗?

    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 的 block 大小在我们的测试中产生了最佳性能。较小的缓冲区大小会显着降低传输速度。我建议您自己进行一些测量,但是 20Kb 对于缓冲区来说肯定太少了。

关于C# : FTP upload buffer size,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10871943/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com