private async Task OnDataReceivedAsync(byte[] messageData) { if (messageData.Length < 4) { LogDebug("Packet ended prematurely on receive"); TransmitError(ETftpErrorType.IllegalOperation, "Packet ended prematurely"); Parent.UnregisterSession(this); return; } var blockNumber = messageData.Get16BE(2); if (blockNumber != ((CurrentBlock + 1) & 0xFFFF)) { LogDebug("Block received out of sequence"); TransmitError(ETftpErrorType.IllegalOperation, "Block received out of sequence"); Parent.UnregisterSession(this); } BytesReceived += messageData.Length - 4; CurrentBlock++; TransmitAck(blockNumber); if (TransferStream == null) { if (CurrentBlock != 1) { LogDebug("ReceiveStream not created yet but not on first packet. Ending transfer"); TransmitError(ETftpErrorType.NotDefined, "Server error"); Parent.UnregisterSession(this); } TransferStream = new MemoryStream(); } TransferStream.Write(messageData, 4, messageData.Length - 4); if (messageData.Length != 516) { LogDebug("Last block received, transfer complete"); await Parent.TransferCompleteAsync(this); } else { if (IdleSince.Subtract(LastMessageTime) > TimeSpan.FromSeconds(1)) { LogDebug("Received " + BytesReceived.ToString() + " bytes so far"); LastMessageTime = IdleSince; } } }
/// <summary> /// Format the data section of a FTP termination record. /// </summary> /// <returns>String representation of a FTP termination record.</returns> public override string ToString() { return(StartTime.ToString().PadRight(22, ' ') + " " + EndTime.ToString().PadRight(22, ' ') + " " + VseTaskId.ToString().PadRight(2 + 5, ' ') + " " + FtpNodeName.PadRight(16, ' ') + " " + FtpUserId.PadRight(8, ' ') + " " + VseIp.PadRight(15, ' ') + " " + VsePort.ToString().PadRight(8, ' ') + " " + ClientPort.ToString().PadRight(11, ' ') + " " + ClientIp.PadRight(15, ' ') + " " + ForeignDataIp.PadRight(15, ' ') + " " + FilesSent.ToString().PadRight(10, ' ') + " " + FilesReceived.ToString().PadRight(10, ' ') + " " + BytesSentAcked.ToString().PadRight(20, ' ') + " " + BytesReceived.ToString().PadRight(20, ' ') + " " + GeneralFlagFormatter(GeneralFlag).PadRight(8, ' ') + " " + SslFlagFormatter(SslFlag).ToString().PadRight(5, ' ')); }
public static void ChangeTrafic(TraficType type, int xbytes) { float bytes = xbytes / 1024f; try { switch (type) { case TraficType.Received: ReceivedPackets++; Winda.Other.Settings.Mainform.listStats.Items[4].SubItems[1].Text = ReceivedPackets.ToString(); BytesReceived = BytesReceived + bytes; Winda.Other.Settings.Mainform.listStats.Items[0].SubItems[1].Text = BytesReceived.ToString(); Winda.Other.Settings.Mainform.listStats.Items[1].SubItems[1].Text = bytes.ToString(); DrawRe((int)xbytes); break; case TraficType.Sent: SentPackets++; BytesSent = BytesSent + bytes; Winda.Other.Settings.Mainform.listStats.Items[2].SubItems[1].Text = BytesSent.ToString(); Winda.Other.Settings.Mainform.listStats.Items[3].SubItems[1].Text = bytes.ToString(); Winda.Other.Settings.Mainform.listStats.Items[5].SubItems[1].Text = SentPackets.ToString(); DrawSe((int)xbytes); break; } } catch { } }