File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -74,15 +74,25 @@ cdef class SCP:
74
74
)
75
75
76
76
try :
77
+ # Read buffer
78
+ read_buffer_size = min (file_size, SCP_MAX_CHUNK)
79
+
77
80
# Begin to send to the file
78
81
rc = libssh.ssh_scp_push_file(scp, filename_b, file_size, file_mode)
79
82
if rc != libssh.SSH_OK:
80
83
raise LibsshSCPException(" Can't open remote file: %s " % self ._get_ssh_error_str())
81
84
82
- # Write to the open file
83
- rc = libssh.ssh_scp_write(scp, PyBytes_AS_STRING(f.read()), file_size)
84
- if rc != libssh.SSH_OK:
85
- raise LibsshSCPException(" Can't write to remote file: %s " % self ._get_ssh_error_str())
85
+ remaining_bytes_to_read = file_size
86
+ while remaining_bytes_to_read > 0 :
87
+ # Read the chunk from local file
88
+ read_bytes = min (remaining_bytes_to_read, read_buffer_size)
89
+ read_buffer = f.read(read_bytes)
90
+
91
+ # Write to the open file
92
+ rc = libssh.ssh_scp_write(scp, PyBytes_AS_STRING(read_buffer), read_bytes)
93
+ if rc != libssh.SSH_OK:
94
+ raise LibsshSCPException(" Can't write to remote file: %s " % self ._get_ssh_error_str())
95
+ remaining_bytes_to_read -= read_bytes
86
96
finally :
87
97
libssh.ssh_scp_close(scp)
88
98
libssh.ssh_scp_free(scp)
You can’t perform that action at this time.
0 commit comments