1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-07-29 13:01:13 +03:00

scp: Support huge files by changing size to 64-bit type.

Signed-off-by: Mark Riordan <mriordan@ipswitch.com>
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
Mark Riordan
2011-04-07 16:40:39 -05:00
committed by Andreas Schneider
parent 3a77f2aebe
commit 96d5f13813
3 changed files with 32 additions and 10 deletions

View File

@ -263,7 +263,7 @@ int ssh_scp_push_directory(ssh_scp scp, const char *dirname, int mode){
}
/**
* @brief Initialize the sending of a file to a scp in sink mode.
* @brief Initialize the sending of a file to a scp in sink mode, using a 64-bit size.
*
* @param[in] scp The scp handle.
*
@ -276,8 +276,10 @@ int ssh_scp_push_directory(ssh_scp scp, const char *dirname, int mode){
*
* @returns SSH_OK if the file is ready to be sent, SSH_ERROR if an
* error occured.
*
* @see ssh_scp_push_file()
*/
int ssh_scp_push_file(ssh_scp scp, const char *filename, size_t size, int mode){
int ssh_scp_push_file64(ssh_scp scp, const char *filename, uint64_t size, int mode){
char buffer[1024];
int r;
uint8_t code;
@ -317,6 +319,25 @@ int ssh_scp_push_file(ssh_scp scp, const char *filename, size_t size, int mode){
return SSH_OK;
}
/**
* @brief Initialize the sending of a file to a scp in sink mode.
*
* @param[in] scp The scp handle.
*
* @param[in] filename The name of the file being sent. It should not contain
* any path indicator
*
* @param[in] size Exact size in bytes of the file being sent.
*
* @param[in] mode The UNIX permissions for the new file, e.g. 0644.
*
* @returns SSH_OK if the file is ready to be sent, SSH_ERROR if an
* error occured.
*/
int ssh_scp_push_file(ssh_scp scp, const char *filename, size_t size, int mode){
return ssh_scp_push_file64(scp, filename, (uint64_t) size, mode);
}
/**
* @internal
*
@ -389,7 +410,7 @@ int ssh_scp_write(ssh_scp scp, const void *buffer, size_t len){
return SSH_ERROR;
}
if(scp->processed + len > scp->filelen)
len = scp->filelen - scp->processed;
len = (size_t) (scp->filelen - scp->processed);
/* hack to avoid waiting for window change */
ssh_channel_poll(scp->channel,0);
w=ssh_channel_write(scp->channel,buffer,len);
@ -476,7 +497,7 @@ int ssh_scp_pull_request(ssh_scp scp){
char buffer[4096];
char *mode=NULL;
char *p,*tmp;
size_t size;
uint64_t size;
char *name=NULL;
int err;
if(scp==NULL)
@ -514,7 +535,7 @@ int ssh_scp_pull_request(ssh_scp scp){
if(p==NULL)
goto error;
*p=0;
size = (size_t) strtoull(tmp,NULL,10);
size = strtoull(tmp,NULL,10);
p++;
name=strdup(p);
SAFE_FREE(scp->request_name);
@ -643,7 +664,7 @@ int ssh_scp_read(ssh_scp scp, void *buffer, size_t size){
return SSH_ERROR;
}
if(scp->processed + size > scp->filelen)
size = scp->filelen - scp->processed;
size = (size_t) (scp->filelen - scp->processed);
if(size > 65536)
size=65536; /* avoid too large reads */
r=ssh_channel_read(scp->channel,buffer,size,0);
@ -701,7 +722,7 @@ int ssh_scp_request_get_permissions(ssh_scp scp){
*
* @returns The numeric size of the file being read.
*/
size_t ssh_scp_request_get_size(ssh_scp scp){
uint64_t ssh_scp_request_get_size(ssh_scp scp){
if(scp==NULL)
return 0;
return scp->filelen;