Skip to content

Commit

Permalink
Merge pull request #19 from JuliaWeb/sftp
Browse files Browse the repository at this point in the history
Moar SFTP moar better
  • Loading branch information
JamesWrigley authored Oct 11, 2024
2 parents 84262d1 + df3a2ea commit 4a4f2e4
Show file tree
Hide file tree
Showing 8 changed files with 531 additions and 115 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "LibSSH"
uuid = "00483490-30f8-4353-8aba-35b82f51f4d0"
authors = ["James Wrigley <[email protected]> and contributors"]
version = "0.5.0"
version = "0.6.0"

[deps]
CEnum = "fa961155-64e5-5f13-b03f-caf6b980ea82"
Expand Down
4 changes: 2 additions & 2 deletions docs/src/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ CurrentModule = LibSSH
This documents notable changes in LibSSH.jl. The format is based on [Keep a
Changelog](https://keepachangelog.com).

## Unreleased
## [v0.6.0] - 2024-10-11

### Added

Expand All @@ -19,7 +19,7 @@ Changelog](https://keepachangelog.com).
- [`close(::SshChannel)`](@ref) and [`closewrite(::SshChannel)`](@ref) now
support an `allow_fail` argument that will print a warning instead of throw an
exception if modifying the `lib.ssh_channel` fails ([#16]).
- Basic [SFTP](sftp.md) support.
- Initial [SFTP](sftp.md) client support ([#16], [#18], [#19]).

### Fixed

Expand Down
38 changes: 36 additions & 2 deletions docs/src/sftp.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,11 @@ Base.close(::SftpSession)
Base.isopen(::SftpSession)
Base.lock(::SftpSession)
Base.unlock(::SftpSession)
Base.stat(::String, ::SftpSession)
Base.readdir(::AbstractString, ::SftpSession)
Base.rm(::AbstractString, ::SftpSession)
Base.mkdir(::AbstractString, ::SftpSession)
Base.mv(::AbstractString, ::AbstractString, ::SftpSession)
Base.stat(::String, ::SftpSession)
get_extensions(::SftpSession)
get_limits(::SftpSession)
get_error(::SftpSession)
Expand Down Expand Up @@ -66,8 +69,39 @@ Base.seekstart(::SftpFile)
Base.seekend(::SftpFile)
```

## File type helpers

```@docs
Base.ispath(::AbstractString, ::SftpSession)
Base.ispath(::SftpAttributes)
Base.isdir(::AbstractString, ::SftpSession)
Base.isdir(::SftpAttributes)
Base.isfile(::AbstractString, ::SftpSession)
Base.isfile(::SftpAttributes)
Base.issocket(::AbstractString, ::SftpSession)
Base.issocket(::SftpAttributes)
Base.islink(::AbstractString, ::SftpSession)
Base.islink(::SftpAttributes)
Base.isblockdev(::AbstractString, ::SftpSession)
Base.isblockdev(::SftpAttributes)
Base.ischardev(::AbstractString, ::SftpSession)
Base.ischardev(::SftpAttributes)
Base.isfifo(::AbstractString, ::SftpSession)
Base.isfifo(::SftpAttributes)
```

## Other types
```@docs
SftpError
SftpAttributes
SftpError
SftpException
```

When an [`SftpException`](@ref) is printed it will be displayed like this:
```@repl
import LibSSH as ssh
ssh.SftpException("Failure", "/tmp/foo", ssh.SftpError_GenericFailure, "SFTP failed", "foo@bar")
```

Note that the SFTP subsystem doesn't always set an error on the
[`Session`](@ref), so take the `Session error` with a grain of salt.
3 changes: 2 additions & 1 deletion gen/gen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ ssh_ok_functions = [:ssh_message_auth_reply_success, :ssh_message_auth_set_metho
threadcall_functions = [:sftp_new, :sftp_init, :sftp_open, :sftp_close,
:sftp_home_directory, :sftp_stat,
:sftp_aio_wait_read, :sftp_aio_wait_write,
:sftp_opendir, :sftp_readdir, :sftp_closedir]
:sftp_opendir, :sftp_readdir, :sftp_closedir,
:sftp_unlink, :sftp_rmdir, :sftp_mkdir, :sftp_rename]
all_rewritable_functions = vcat(string_functions, bool_functions, ssh_ok_functions, threadcall_functions)

"""
Expand Down
72 changes: 60 additions & 12 deletions src/bindings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3637,8 +3637,19 @@ function sftp_rewind(file)
@ccall libssh.sftp_rewind(file::sftp_file)::Cvoid
end

function _threadcall_sftp_unlink(sftp::sftp_session, file::Ptr{Cchar})
gc_state = @ccall(jl_gc_safe_enter()::Int8)
ret = @ccall(libssh.sftp_unlink(sftp::sftp_session, file::Ptr{Cchar})::Cint)
@ccall jl_gc_safe_leave(gc_state::Int8)::Cvoid
return ret
end

"""
sftp_unlink(sftp, file)
sftp_unlink(sftp::sftp_session, file::Ptr{Cchar})
Auto-generated wrapper around `sftp_unlink()`. Original upstream documentation is below.
---
Unlink (delete) a file.
Expand All @@ -3650,12 +3661,24 @@ Unlink (delete) a file.
# See also
[`sftp_get_error`](@ref)()
"""
function sftp_unlink(sftp, file)
@ccall libssh.sftp_unlink(sftp::sftp_session, file::Ptr{Cchar})::Cint
function sftp_unlink(sftp::sftp_session, file::Ptr{Cchar})
cfunc = @cfunction(_threadcall_sftp_unlink, Cint, (sftp_session, Ptr{Cchar}))
return @threadcall(cfunc, Cint, (sftp_session, Ptr{Cchar}), sftp, file)
end

function _threadcall_sftp_rmdir(sftp::sftp_session, directory::Ptr{Cchar})
gc_state = @ccall(jl_gc_safe_enter()::Int8)
ret = @ccall(libssh.sftp_rmdir(sftp::sftp_session, directory::Ptr{Cchar})::Cint)
@ccall jl_gc_safe_leave(gc_state::Int8)::Cvoid
return ret
end

"""
sftp_rmdir(sftp, directory)
sftp_rmdir(sftp::sftp_session, directory::Ptr{Cchar})
Auto-generated wrapper around `sftp_rmdir()`. Original upstream documentation is below.
---
Remove a directory.
Expand All @@ -3667,12 +3690,24 @@ Remove a directory.
# See also
[`sftp_get_error`](@ref)()
"""
function sftp_rmdir(sftp, directory)
@ccall libssh.sftp_rmdir(sftp::sftp_session, directory::Ptr{Cchar})::Cint
function sftp_rmdir(sftp::sftp_session, directory::Ptr{Cchar})
cfunc = @cfunction(_threadcall_sftp_rmdir, Cint, (sftp_session, Ptr{Cchar}))
return @threadcall(cfunc, Cint, (sftp_session, Ptr{Cchar}), sftp, directory)
end

function _threadcall_sftp_mkdir(sftp::sftp_session, directory::Ptr{Cchar}, mode::mode_t)
gc_state = @ccall(jl_gc_safe_enter()::Int8)
ret = @ccall(libssh.sftp_mkdir(sftp::sftp_session, directory::Ptr{Cchar}, mode::mode_t)::Cint)
@ccall jl_gc_safe_leave(gc_state::Int8)::Cvoid
return ret
end

"""
sftp_mkdir(sftp, directory, mode)
sftp_mkdir(sftp::sftp_session, directory::Ptr{Cchar}, mode::mode_t)
Auto-generated wrapper around `sftp_mkdir()`. Original upstream documentation is below.
---
Create a directory.
Expand All @@ -3685,12 +3720,24 @@ Create a directory.
# See also
[`sftp_get_error`](@ref)()
"""
function sftp_mkdir(sftp, directory, mode)
@ccall libssh.sftp_mkdir(sftp::sftp_session, directory::Ptr{Cchar}, mode::mode_t)::Cint
function sftp_mkdir(sftp::sftp_session, directory::Ptr{Cchar}, mode::mode_t)
cfunc = @cfunction(_threadcall_sftp_mkdir, Cint, (sftp_session, Ptr{Cchar}, mode_t))
return @threadcall(cfunc, Cint, (sftp_session, Ptr{Cchar}, mode_t), sftp, directory, mode)
end

function _threadcall_sftp_rename(sftp::sftp_session, original::Ptr{Cchar}, newname::Ptr{Cchar})
gc_state = @ccall(jl_gc_safe_enter()::Int8)
ret = @ccall(libssh.sftp_rename(sftp::sftp_session, original::Ptr{Cchar}, newname::Ptr{Cchar})::Cint)
@ccall jl_gc_safe_leave(gc_state::Int8)::Cvoid
return ret
end

"""
sftp_rename(sftp, original, newname)
sftp_rename(sftp::sftp_session, original::Ptr{Cchar}, newname::Ptr{Cchar})
Auto-generated wrapper around `sftp_rename()`. Original upstream documentation is below.
---
Rename or move a file or directory.
Expand All @@ -3703,8 +3750,9 @@ Rename or move a file or directory.
# See also
[`sftp_get_error`](@ref)()
"""
function sftp_rename(sftp, original, newname)
@ccall libssh.sftp_rename(sftp::sftp_session, original::Ptr{Cchar}, newname::Ptr{Cchar})::Cint
function sftp_rename(sftp::sftp_session, original::Ptr{Cchar}, newname::Ptr{Cchar})
cfunc = @cfunction(_threadcall_sftp_rename, Cint, (sftp_session, Ptr{Cchar}, Ptr{Cchar}))
return @threadcall(cfunc, Cint, (sftp_session, Ptr{Cchar}, Ptr{Cchar}), sftp, original, newname)
end

"""
Expand Down
Loading

0 comments on commit 4a4f2e4

Please sign in to comment.