Esempio n. 1
0
		/// <summary>Initiate a file download from the server.</summary>
		/// <param name="stream">Data stream to write to.</param>
		/// <param name="channel">The channel id to download from.</param>
		/// <param name="path">The download path within the channel. Eg: "file.txt", "path/file.png"</param>
		/// <param name="channelPassword">The password for the channel.</param>
		/// <param name="closeStream">True will <see cref="IDisposable.Dispose"/> the stream after the download is finished.</param>
		/// <returns>A token to track the file transfer.</returns>
		public R<FileTransferToken, CommandError> DownloadFile(Stream stream, ChannelIdT channel, string path, string channelPassword = "", bool closeStream = true)
		{
			ushort cftid = GetFreeTransferId();
			var request = parent.FileTransferInitDownload(channel, path, channelPassword, cftid, 0);
			if (!request.Ok)
			{
				if (closeStream) stream.Close();
				return request.Error;
			}
			var token = new FileTransferToken(stream, request.Value, channel, path, channelPassword, 0) { CloseStreamWhenDone = closeStream };
			StartWorker(token);
			return token;
		}
        public FileTransferToken DownloadFile(Stream stream, ChannelIdT channel, string path, string channelPassword = "", bool closeStream = false)
        {
            ushort cftid   = GetFreeTransferId();
            var    request = parent.FileTransferInitDownload(channel, path, channelPassword, cftid, 0);

            if (!string.IsNullOrEmpty(request.Message))
            {
                throw new Ts3Exception(request.Message);
            }
            var token = new FileTransferToken(stream, request, channel, path, channelPassword, 0)
            {
                CloseStreamWhenDone = closeStream
            };

            StartWorker(token);
            return(token);
        }