Comments (5)
I experienced the same issue you are referring here and I in my case the issue was that I was not disconnecting the channel properly and waiting for transfer completion, so the TCP connection was literally killed before it finished to send all the data.
Example of working code:
use std::io::prelude::*;
use std::net::TcpStream;
use std::path::Path;
use ssh2::Session;
// Connect to the local SSH server
let tcp = TcpStream::connect("127.0.0.1:22").unwrap();
let mut sess = Session::new().unwrap();
sess.set_tcp_stream(tcp);
sess.handshake().unwrap();
sess.userauth_agent("username").unwrap();
let mut remote_file = sess.scp_send(Path::new("remote"),
0o644, 10, None).unwrap();
remote_file.write_all(b"1234567890").unwrap();
remote_file.send_eof().unwrap();
remote_file.wait_eof().unwrap();
remote_file.close().unwrap();
remote_file.wait_close().unwrap();
The magic is in the last 4 lines, where i am actually telling the channel that we are at EOF, waiting for EOF from the server, closing the channel and waiting the channel to be actually closed.
Without the wait_close()
the underlying TCP/SSH connection can be severed before the file transfer has finished.
I think this is not really clear in the documentation, but it is not this crate fault IMO.. I had to read a bunch of C code from libssh2 before understanding all this..
from ssh2-rs.
@crisidev That's great - thanks for sharing.
from ssh2-rs.
Hm I wonder if this is maybe an accidental integer overflow? In general this library is just a thin wrapper so the issue may be with libssh2?
from ssh2-rs.
Gosh, it's actually file.write vs file.write_all issue. So once I swapped the method I'm calling it works fine. Thanks.
from ssh2-rs.
Spoke too soon, changing to write_all worked on dev machine to dev server. But when we tried against production it failed around 1 MB this time. I initially thought it culd be musl build so tried with gnu libc build it still had the same issue. So currently I've moved it to use SFTP and that seems to consistently write all the data so far. The weird thing with scp_send had different limits based on which server we were pushing data to. Switching to SFTP for now as I don't have a lot of time to debug this issue but it would be good to get to the bottom of it (or at least understand why it fails quietly).
from ssh2-rs.
Related Issues (20)
- ```userauth_pubkey_memory()``` not working.
- Help communicating with a device HOT 1
- Cipher suite mystery HOT 1
- Unable to build HOT 2
- please include license texts in distributed libssh2-sys crates
- ScpFileStat is currently unusable HOT 2
- Can't directly read/write to channel HOT 2
- Mangaro linux can't compile HOT 1
- channel::shell() test occasionally deadlocks on MacOS HOT 1
- Consider modifying parameters for this method : channel::request_pty_size() HOT 2
- Full-duplex compatability
- Update dependency `bitflags` to v2?
- inspecting SSH agent deadlocks on windows
- transport read
- Prefix truncation breaking SSH channel integrity aka Terrapin Attack (CVE-2023-48795)
- session handshake on error 43 HOT 3
- Non standard SSH agent is not working HOT 1
- does not build on an esp32 HOT 1
- keyboard-interactive authentication panics - with a potential fix
- panic Utf8Error
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ssh2-rs.