Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SZERVEROLDAL:
- case FtpPacket.FileDownloadPacket:
- Log("File download packet");
- Log("Everything sent: " + _isEverythingSent.ToString().ToUpper());
- try
- {
- if (_isEverythingSent)
- {
- Log("Everything is sent!");
- Send(Values.Success);
- return true;
- }
- if (!_isFilenameSet)
- {
- Log("Send: no filename");
- Send(Values.NoFilename);
- return true;
- }
- Log("Filebuffer length: " + _fileBuffer.Length);
- if (_fileBuffer.Length > CHUNK_SIZE) // file is smaller than CHUNK_SIZE, can be sent in one packet
- {
- Log("Filesize is bigger than 1024");
- Log("| current chunk index: " + _currentChunkIndex);
- if (_fileBuffer.Length - _currentChunkIndex > CHUNK_SIZE)
- {
- Log("The remaining data: " + (_fileBuffer.Length - _currentChunkIndex));
- var tmp = GetSubArray(_fileBuffer, _currentChunkIndex, _fileBuffer.Length - _currentChunkIndex);
- Send(tmp);
- Console.WriteLine(tmp.GetString());
- _currentChunkIndex += CHUNK_SIZE;
- }
- else
- {
- Log("Filesize is less then 1024");
- var tmp = GetSubArray(_fileBuffer, _currentChunkIndex, _fileBuffer.Length - _currentChunkIndex);
- Send(tmp);
- Console.WriteLine(tmp.GetString());
- _isEverythingSent = true;
- }
- }
- else
- {
- Log("Send: filebuffer - " + _fileBuffer.GetString());
- Send(_fileBuffer);
- _isEverythingSent = true;
- }
- }
- catch (Exception e)
- {
- Log(e.Message + "\n" + e);
- Send(Values.Denied);
- ResetState();
- }
- return true;
- KLIENSOLDAL:
- // Start downloading
- const int CHUNK_SIZE = 1024;
- List<byte> fileContent = new List<byte>();
- List<string> testList = new List<string>();
- bool succeeded = false;
- bytes = new byte[CHUNK_SIZE];
- while (true) // FileDownloadPacket
- {
- Send(Values.Download);
- Send(Values.Endvalue, true);
- Recieve(bytes);
- //Console.WriteLine(bytes.GetString());
- if (bytes.MembersEquals(Values.Success, 2))
- {
- succeeded = true;
- break;
- }
- else if (bytes.MembersEquals(Values.Denied, 2) || bytes.MembersEquals(Values.NoFilename, 2))
- {
- break;
- }
- testList.Add(bytes.GetString());
- fileContent.AddRange(bytes);
- bytes = new byte[CHUNK_SIZE];
- }
- return succeeded ? fileContent.ToArray() : null;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement