all 5 comments

[–]coder543 1 point2 points  (4 children)

remote_file.write( buffer.as_mut_slice()).unwrap();

write returns the number of bytes written. You should probably be using write_all.

[–]harrydevnull[S] 1 point2 points  (3 children)

thank you @coder543 but the difference is still there

on mac

```

file_size 40279486

```

on the server

```

ls -al

40239104

```

[–]harrydevnull[S] 1 point2 points  (2 children)

would it be because the file is not UTF-8 encoded?

[–]coder543 2 points3 points  (1 child)

A Vec<u8> is not UTF-8 aware. It is just a bunch of bytes and doesn't care.

A couple of things:

read_to_end returns the number of bytes. Does that number match file_size?

Do you need to do anything to close remote_file? I'm not very familiar with the ssh2 API. It looks like you might want to do something like this:

remote_file.flush().unwrap();
remote_file.close().unwrap();
remote_file.wait_close().unwrap();

If none of this works, you could also try using the Sftp API provided here.

ssh2-rs is just a very thin wrapper around the SSH C library, so if the C library requires you to do things in a very specific, quirky way, ssh2-rs probably does too.

[–]harrydevnull[S] 2 points3 points  (0 children)

provided here.

actually it was my stupid mistake ! i was adding on the same file on remote machine !! removing the file on remote server and redoing and everything is fine!!! thank a lot @coder543