Coder Social home page Coder Social logo

scp_send stops at 16KB about ssh2-rs HOT 5 CLOSED

alexcrichton avatar alexcrichton commented on August 15, 2024
scp_send stops at 16KB

from ssh2-rs.

Comments (5)

crisidev avatar crisidev commented on August 15, 2024 1

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.

opensourcegeek avatar opensourcegeek commented on August 15, 2024 1

@crisidev That's great - thanks for sharing.

from ssh2-rs.

alexcrichton avatar alexcrichton commented on August 15, 2024

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.

opensourcegeek avatar opensourcegeek commented on August 15, 2024

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.

opensourcegeek avatar opensourcegeek commented on August 15, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.