mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-09 09:54:25 +09:00
Fixed ssh_scp_write so it works when doing recursive copy
There where two issues with ssh_scp_write:
1) It did not write a status message after the last write and OpenSSH
would then give up after the write finished.
2) OpenSSH would sometimes write a status message, after near ends write.
If scp_write didn't handle it, and subsequent status message. The remote
window would shrink to zero and ssh_channel_write would start returning 0.
Signed-off-by: Einar Floystad Dorum <einarfd@mailthief.com>
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
(cherry picked from commit 01c4b713dc)
This commit is contained in:
committed by
Andreas Schneider
parent
1204f43ea9
commit
edb03bd224
30
src/scp.c
30
src/scp.c
@@ -380,8 +380,8 @@ int ssh_scp_response(ssh_scp scp, char **response){
|
|||||||
*/
|
*/
|
||||||
int ssh_scp_write(ssh_scp scp, const void *buffer, size_t len){
|
int ssh_scp_write(ssh_scp scp, const void *buffer, size_t len){
|
||||||
int w;
|
int w;
|
||||||
//int r;
|
int r;
|
||||||
//uint8_t code;
|
uint8_t code;
|
||||||
if(scp==NULL)
|
if(scp==NULL)
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
if(scp->state != SSH_SCP_WRITE_WRITING){
|
if(scp->state != SSH_SCP_WRITE_WRITING){
|
||||||
@@ -400,19 +400,27 @@ int ssh_scp_write(ssh_scp scp, const void *buffer, size_t len){
|
|||||||
//return=channel_get_exit_status(scp->channel);
|
//return=channel_get_exit_status(scp->channel);
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
|
/* Far end sometimes send a status message, which we need to read
|
||||||
|
* and handle */
|
||||||
|
r = ssh_channel_poll(scp->channel,0);
|
||||||
|
if(r > 0){
|
||||||
|
r = ssh_channel_read(scp->channel, &code, 1, 0);
|
||||||
|
if(r == SSH_ERROR){
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
if(code == 1 || code == 2){
|
||||||
|
ssh_set_error(scp->session,SSH_REQUEST_DENIED, "SCP: Error: status code %i received", code);
|
||||||
|
return SSH_ERROR;
|
||||||
|
}
|
||||||
|
}
|
||||||
/* Check if we arrived at end of file */
|
/* Check if we arrived at end of file */
|
||||||
if(scp->processed == scp->filelen) {
|
if(scp->processed == scp->filelen) {
|
||||||
/* r=channel_read(scp->channel,&code,1,0);
|
code = 0;
|
||||||
if(r==SSH_ERROR){
|
w = ssh_channel_write(scp->channel, &code, 1);
|
||||||
scp->state=SSH_SCP_ERROR;
|
if(w == SSH_ERROR){
|
||||||
|
scp->state = SSH_SCP_ERROR;
|
||||||
return SSH_ERROR;
|
return SSH_ERROR;
|
||||||
}
|
}
|
||||||
if(code != 0){
|
|
||||||
ssh_set_error(scp->session,SSH_FATAL, "scp status code %ud not valid", code);
|
|
||||||
scp->state=SSH_SCP_ERROR;
|
|
||||||
return SSH_ERROR;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
scp->processed=scp->filelen=0;
|
scp->processed=scp->filelen=0;
|
||||||
scp->state=SSH_SCP_WRITE_INITED;
|
scp->state=SSH_SCP_WRITE_INITED;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user