TCP ストリームから読み込んでいます - 「MLSD」コマンド (ファイル/ディレクトリ情報の取得) を使用して FTP サーバーにクエリを実行しました。応答サイズは可変であるため(ファイル/ディレクトリなどの量に依存)、「バッファ」を何バイトに設定する必要があるかわかりません。すべてのデータが tcp ストリームを介して FTP サーバーから取得されるようにするにはどうすればよいですか?
private string controlListener(int controlPort)
{
try
{
// Create a TcpClient.
// Note, for this client to work you need to have a TcpServer
// connected to the same address as specified by the server, port
// combination.
controlClient = new TcpClient(ftpHost, controlPort);
// Get a client stream for reading and writing.
controlStream = controlClient.GetStream();
// Because we don't know how many bytes are incoming for welcome message - we use a 2 second delay to retrieve all bytes within that time frame.
// Receive the TcpServer.response.
// Buffer to store the response bytes.
Byte[] data = new Byte[4096];
// String to store the response ASCII representation.
String responseData = String.Empty;
// Get Control Stream Responce: Read the first batch of the TcpServer response bytes.
Int32 bytes = controlStream.Read(data, 0, data.Length);
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
Console.WriteLine(responseData);
return responseData;
}