public FileTransferToken(Stream localStream, ushort cftid, ushort sftid,
                          TransferDirection dir, ChannelId channelId, string path, string channelPassword, ushort port, long seekPos,
                          string transferKey, long size, bool createMd5)
 {
     CloseStreamWhenDone = false;
     Status           = TransferStatus.Waiting;
     LocalStream      = localStream;
     Direction        = dir;
     ClientTransferId = cftid;
     ServerTransferId = sftid;
     ChannelId        = channelId;
     Path             = path;
     ChannelPassword  = channelPassword;
     Port             = port;
     SeekPosition     = seekPos;
     TransferKey      = transferKey;
     Size             = size;
     CreateMd5        = createMd5;
 }
        /// <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, ChannelId 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);
        }
Example #3
0
 public Task <R <PermOverview[], CommandError> > PermOverview(ClientDbId clientDbId, ChannelId channelId, params TsPermission[] permission)
 => SendHybrid <PermOverview>(new TsCommand("permoverview")
 {
     { "cldbid", clientDbId },
     { "cid", channelId },
     TsPermissionHelper.GetAsMultiParameter(Deserializer.PermissionTransform, permission)
 }, NotificationType.PermOverview);
Example #4
0
 public abstract Task <R <FileDownload, CommandError> > FileTransferInitDownload(ChannelId channelId, string path, string channelPassword,
                                                                                 ushort clientTransferId, long seek);
Example #5
0
 public abstract Task <R <FileUpload, CommandError> > FileTransferInitUpload(ChannelId channelId, string path, string channelPassword,
                                                                             ushort clientTransferId, long fileSize, bool overwrite, bool resume);
Example #6
0
 public CmdR ChannelDelete(ChannelId channelId, bool force = false)
 => SendVoid(new TsCommand("channeldelete")
 {
     { "cid", channelId },
     { "force", force },
 });
Example #7
0
 /// <summary>Displays detailed configuration information about a channel including ID, topic, description, etc.
 /// For detailed information, see Channel Properties.</summary>
 public Task <R <ChannelInfoResponse[], CommandError> > ChannelInfo(ChannelId channelId)
 => Send <ChannelInfoResponse>(new TsCommand("channelinfo")
 {
     { "cid", channelId },
 });
        /// <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 async Task <R <FileTransferToken, CommandError> > DownloadFile(Stream stream, ChannelId channel, string path, string channelPassword = "", bool closeStream = true)
        {
            ushort cftid   = GetFreeTransferId();
            var    request = await FileTransferInitDownload(channel, path, channelPassword, cftid, 0);

            if (!request.Ok)
            {
                if (closeStream)
                {
#if NETSTANDARD2_0
                    stream.Dispose();
#else
                    await stream.DisposeAsync();
#endif
                }
                return(request.Error);
            }
            var token = new FileTransferToken(stream, request.Value, channel, path, channelPassword, 0)
            {
                CloseStreamWhenDone = closeStream
            };
            return(await Transfer(token));
        }
 /// <summary>Initiate a file download from the server.</summary>
 /// <param name="file">Local file to save 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>
 /// <returns>A token to track the file transfer.</returns>
 public Task <R <FileTransferToken, CommandError> > DownloadFile(IOFileInfo file, ChannelId channel, string path, string channelPassword = "")
 => DownloadFile(file.Open(FileMode.Create, FileAccess.Write), channel, path, channelPassword, true);
 public FileTransferToken(Stream localStream, FileDownload download, ChannelId channelId,
                          string path, string channelPassword, long seekPos)
     : this(localStream, download.ClientFileTransferId, download.ServerFileTransferId, TransferDirection.Download,
            channelId, path, channelPassword, download.Port, seekPos, download.FileTransferKey, (long)download.Size, false)
 {
 }
 public FileTransferToken(Stream localStream, FileUpload upload, ChannelId channelId,
                          string path, string channelPassword, long size, bool createMd5)
     : this(localStream, upload.ClientFileTransferId, upload.ServerFileTransferId, TransferDirection.Upload,
            channelId, path, channelPassword, upload.Port, (long)upload.SeekPosition, upload.FileTransferKey, size, createMd5)
 {
 }
 /// <summary>Initiate a file upload to the server.</summary>
 /// <param name="file">Local file 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>
 /// <returns>A token to track the file transfer.</returns>
 public Task <R <FileTransferToken, CommandError> > UploadFile(IOFileInfo file, ChannelId channel, string path, bool overwrite = false, string channelPassword = "")
 => UploadFile(file.Open(FileMode.Open, FileAccess.Read), channel, path, overwrite, channelPassword);