Renci.SshNet.SftpClient.DeleteDirectory C# (CSharp) Method

DeleteDirectory() public method

Deletes remote directory specified by path.
is null or contains only whitespace characters. Client is not connected. was not found on the remote host. Permission to delete the directory was denied by the remote host. -or- A SSH command was denied by the server. A SSH error where is the message from the remote host. The method was called after the client was disposed.
public DeleteDirectory ( string path ) : void
path string Directory to be deleted path.
return void
        public void DeleteDirectory(string path)
        {
            CheckDisposed();

            if (path.IsNullOrWhiteSpace())
                throw new ArgumentException("path");

            if (_sftpSession == null)
                throw new SshConnectionException("Client not connected.");

            var fullPath = _sftpSession.GetCanonicalPath(path);

            _sftpSession.RequestRmDir(fullPath);
        }

Usage Example

Beispiel #1
0
        public override async Task Remove(string cpath, bool isFolder = false)
        {
            var caughtException = default(Exception);
            await Task.Run(() =>
            {
                try
                {
                    if (isFolder)
                    {
                        _sftpc.DeleteDirectory(cpath);
                    }
                    else
                    {
                        _sftpc.Delete(cpath);
                    }
                }
                catch (Exception ex)
                {
                    ex.LogException();
                    caughtException = ex;
                }
            });

            if (caughtException != default(Exception))
            {
                throw caughtException;
            }
        }
All Usage Examples Of Renci.SshNet.SftpClient::DeleteDirectory