public void ReceiveFile(Session Session, string Filename) { string fn = Filename; int fc = 0; while (System.IO.File.Exists(fn)) { fc += 1; fn = filename + "." + fc.ToString("d3"); if (fc >= 1000) { throw new Exception("Could not save file \"" + filename + "\"."); } } stream = new FileStream(fn, FileMode.Create); this.filename = fn; CurrentBlock = 1; FilePosition = 0; Open(Session); Display.PrintSeparater(); Display.PrintLine("Receiving file: " + filename + "\r\n"); Mode = TransferModes.Receiving; Stage = TransferStages.Waiting; ResetNAKTimer(); StartTimer(); SendNAK(); }
private void CompleteReceive() { int fc = 0; string fn = filename; FilePosition += DATA_LENGTH; Stage = TransferStages.Complete; stream.Close(); Close(true); }
protected virtual void AppendData() { Display.Print(spinner[spinnerIndex]); spinnerIndex = (spinnerIndex + 1) % spinner.Length; Display.MoveLeft(); byte b = dataBuffer.Peek(); if (dataBuffer.Count >= BLOCK_LENGTH) { // SOH begins an XMODEM block // read until we get a valid SOH and then // enter the block. if (b == SOH) { Stage = TransferStages.Data; ProcessBuffer(); } else { dataBuffer.Read(); } } if (b == ETX) // cancel { dataBuffer.Read(); Display.PrintSeparater(); Display.PrintAtStart("Canceled by remote host."); Cancel(); } else if (b == EOT) { dataBuffer.Read(); SendACK(); CompleteReceive(); } }
public void Cancel() { //Display.PrintAtStart("Transfer canceled."); Stage = TransferStages.Fail; Close(false); }