/// <summary> /// Uploads stream into remote file. /// </summary> /// <param name="input">Data input stream.</param> /// <param name="path">Remote file path.</param> /// <param name="canOverride">if set to <c>true</c> then existing file will be overwritten.</param> /// <param name="uploadCallback">The upload callback.</param> /// <exception cref="ArgumentNullException"><paramref name="input" /> is <b>null</b>.</exception> /// <exception cref="ArgumentException"><paramref name="path" /> is <b>null</b> or contains only whitespace characters.</exception> /// <exception cref="SshConnectionException">Client is not connected.</exception> /// <exception cref="SftpPermissionDeniedException">Permission to upload the file was denied by the remote host. <para>-or-</para> A SSH command was denied by the server.</exception> /// <exception cref="SshException">A SSH error where <see cref="P:System.Exception.Message" /> is the message from the remote host.</exception> /// <exception cref="ObjectDisposedException">The method was called after the client was disposed.</exception> /// <remarks> /// Method calls made by this method to <paramref name="input" />, may under certain conditions result in exceptions thrown by the stream. /// </remarks> public bool UploadAndCreateFile(Stream input, string remoteProjectDir, string remoteRelativeDir, string fileName, CancellationToken cancelToken, bool canOverride = true, Action <ulong> uploadCallback = null) { remoteRelativeDir = FileTools.NormalizeDirName(remoteRelativeDir); remoteProjectDir = FileTools.NormalizeDirName(remoteProjectDir); string absoluteDir = FileTools.CombinePaths(remoteProjectDir, remoteRelativeDir); //string dir = remoteRelativeDir;//GetRemoteDirectoryName(path); try { if ((cancelToken != null) && cancelToken.IsCancellationRequested) { cancelToken.ThrowIfCancellationRequested(); } if (!EnterDirectory(absoluteDir)) { return(false); } if (!ChangeDirectory(absoluteDir)) { return(false); } if (!UploadFile(input, fileName, cancelToken, canOverride, OnUploadProgress)) { return(false); } } catch (ObjectDisposedException eDisposed) { return(false); } return(true); }