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");
}
}