Ejemplo n.º 1
0
		/// <summary>Initiate a file upload to the server.</summary>
		/// <param name="stream">Data stream to upload.</param>
		/// <param name="channel">The channel id to upload to.</param>
		/// <param name="path">The upload path within the channel. Eg: "file.txt", "path/file.png"</param>
		/// <param name="overwrite">True if the upload should overwrite the file if it exists.
		/// False will throw an exception if the file already exists.</param>
		/// <param name="channelPassword">The password for the channel.</param>
		/// <param name="closeStream">True will <see cref="IDisposable.Dispose"/> the stream after the upload is finished.</param>
		/// <param name="createMd5">Will generate a md5 sum of the uploaded file.</param>
		/// <returns>A token to track the file transfer.</returns>
		public R<FileTransferToken, CommandError> UploadFile(Stream stream, ChannelIdT channel, string path, bool overwrite = false, string channelPassword = "", bool closeStream = true, bool createMd5 = false)
		{
			ushort cftid = GetFreeTransferId();
			var request = parent.FileTransferInitUpload(channel, path, channelPassword, cftid, stream.Length, overwrite, false);
			if (!request.Ok)
			{
				if (closeStream) stream.Close();
				return request.Error;
			}
			var token = new FileTransferToken(stream, request.Value, channel, path, channelPassword, stream.Length, createMd5) { CloseStreamWhenDone = closeStream };
			StartWorker(token);
			return token;
		}
Ejemplo n.º 2
0
        public FileTransferToken UploadFile(Stream stream, ChannelIdT channel, string path, bool overwrite = false, string channelPassword = "")
        {
            ushort cftid   = GetFreeTransferId();
            var    request = parent.FileTransferInitUpload(channel, path, channelPassword, cftid, stream.Length, overwrite, false);

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

            StartWorker(token);
            return(token);
        }