# Julia wrapper for libssh?

**URL:** https://discourse.julialang.org/t/julia-wrapper-for-libssh/46041
**Category:** Data
**Created:** [September 4, 2020, 5:46am UTC](https://discourse.julialang.org/t/julia-wrapper-for-libssh/46041 "2020-09-04T05:46:22Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![grero](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/grero/32/109_2.png) [@grero](https://discourse.julialang.org/u/grero)
#### Post date: [September 4, 2020, 5:46am UTC](https://discourse.julialang.org/t/julia-wrapper-for-libssh/46041/1 "2020-09-04T05:46:22Z")

</div>

Is there a julia wrapper for libssh somewhere? I would like to be able to transfer a part of a large file located on a remote server using sftp (the file itself could be 100G, but I might be interested in a small subset of the data contained in that file). I realise this could be solved by splitting up the data into smaller files, but I have quite a number of these large files generated by a different process and I’d like to avoid having to split them up.

It would be really cool if something like this worked:

```julia
using SSH
data = open(SSH.new_session("username","password")) do session
   data = SSH.sftp_open(session, "remotefile") do ff
    SSH.sftp.seek(session, ff, pos)
    data = SSH.sftp.read(session, ff, bytes)
 end
end

```

---

<div class="post-metadata">

### Author: ![grero](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/grero/32/109_2.png) [@grero](https://discourse.julialang.org/u/grero)
#### Post date: [September 15, 2020, 9:15am UTC](https://discourse.julialang.org/t/julia-wrapper-for-libssh/46041/2 "2020-09-15T09:15:09Z")

</div>

I started working on [RemoteFiles](https://github.com/grero/RemoteFiles.jl) that will hopefully end up solving my problem.

---

<div class="post-metadata">

### Author: ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)
#### Post date: [September 15, 2020, 10:12am UTC](https://discourse.julialang.org/t/julia-wrapper-for-libssh/46041/3 "2020-09-15T10:12:41Z")

</div>

No idea whether anyone wrote a wrapper around libssh already, but note that we have [`OpenSSH_jll`](https://github.com/JuliaBinaryWrappers/OpenSSH_jll.jl) which provide OpenSSH on all platforms. Note also a package called [`RemoteFiles.jl`](https://github.com/helgee/RemoteFiles.jl) already exists.

---

<div class="post-metadata">

### Author: ![grero](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/grero/32/109_2.png) [@grero](https://discourse.julialang.org/u/grero)
#### Post date: [September 16, 2020, 4:05am UTC](https://discourse.julialang.org/t/julia-wrapper-for-libssh/46041/4 "2020-09-16T04:05:03Z")

</div>

Thanks for pointing out the name clash, I will rename my package then. Also, thanks for pointing out OpenSSH\_jll, I’ll definitely have a look at that.

---

<div class="post-metadata">

### Author: ![grero](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/grero/32/109_2.png) [@grero](https://discourse.julialang.org/u/grero)
#### Post date: [December 14, 2020, 9:03am UTC](https://discourse.julialang.org/t/julia-wrapper-for-libssh/46041/5 "2020-12-14T09:03:03Z")

</div>

Just to post a tiny update to this, I renamed my repo [SecureRemoteFiles](https://github.com/grero/SecureRemoteFiles.jl/tree/master) to avoid the name clash. Adding the Secure- prefix seemed appropriate because the package is built on top of sftp. As such, it requires that you have ssh access to the sever hosting the remote file you are interested in.  
You can use standard file handling methods, such as open and read, which will then be forwarded over sftp. The following is a short (silly) example

```julia
using SecureRemoteFiles

# create a file to read from
open("/tmp/testfile.txt","w") do f
   write(f, "This is a test")
end

# read the file contents back over sftp
data = open(sftp"localhost:/tmp/testfile.txt",0) do ff
    read(ff, 14)
end
txt = unsafe_string(pointer(data), length(data))

```

It is still very much a work in progress, but I’ve successfully incorporated this package into a visualisation tool that allows me to look at snapshots of data from electrophysiology experiments without having to download the whole file to my laptop. Once I’ve polished that up a bit, I hope to be able to put it out there for anyone interested in taking a look.
