/// <summary> /// Requests a remote file with its header. All further information is specfied in the <see cref="FTEventArgs"/>. After a <see cref="FileMeta"/> was received you can start the actual download with <see cref="ContinueAsync(FTEventArgs)"/>. /// </summary> /// <param name="e">Specifies an identifier for the remote file, a local path and many more information of the file to download.</param> public Task <bool> StartDownloadAsync(FTEventArgs e) { e.Assign(parent, this); e.Mode = StreamMode.GetFile; currentItem = e; return(parent.Manager.SendPacketAsync(new P07OpenFileTransfer(e.Identifier, e.Mode))); }
/// <summary> /// Accepts a DownloadHeader or DownloadFile request with custom metadata. /// </summary> /// <param name="e">The related request with many important information.</param> /// <param name="path">Local path where the file currently exists or will be stored.</param> /// <param name="meta">Only for file sending! The metadata to send especially for E2E server applications.</param> public async Task <bool> AcceptAsync(FTEventArgs e, string path, FileMeta meta) { e.Path = path; e.Assign(parent, this); e.FileMeta = meta; currentItem = e; if (!await parent.Manager.SendPacketAsync(new P06Accepted(true, 7, ProblemCategory.None))) // accept the transfer { return(false); } if (currentItem.Mode == StreamMode.PushHeader || currentItem.Mode == StreamMode.PushFile) // start by sending the FileMeta { if (currentItem.FileMeta == null) { currentItem.FileMeta = await FileMeta.FromFileAsync(path, ContentAlgorithm.None); } if (!await parent.Manager.SendPacketAsync(new P08FileHeader(currentItem.FileMeta.GetBinaryData(parent.ConnectionVersion.Value)))) { return(false); } } else if (meta != null) { throw new ArgumentException("You must not supply a FileMeta for a receive operation.", nameof(meta)); } return(true); }
/// <summary> /// Cancels a pending request or a running file transfer. /// </summary> /// <param name="e"></param> public Task <bool> CancelAsync(FTEventArgs e) { Task <bool> t = parent.Manager.SendPacketAsync(new P06Accepted(false, 7, ProblemCategory.None)); // This packet cancels any request or running transfer. e.Assign(parent, this); // This assignment is necessary for FTEventArgs to print exceptions and raise events. e.Finish(success: false); currentItem = null; return(t); }
/// <summary> /// Requests the permission to upload a file with its header. All further information is specfied in the <see cref="FTEventArgs"/>. /// </summary> /// <param name="e">Specifies an remote identifier for the file, a local path and many more information of the file to upload.</param> public Task <bool> StartUploadAsync(FTEventArgs e) { e.Assign(parent, this); e.Mode = StreamMode.PushFile; currentItem = e; var packet = new P07OpenFileTransfer(e.Identifier, e.Mode); packet.PrepareSend(parent.ConnectionVersion.Value); return(parent.Manager.SendPacketAsync(packet)); }