Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions scp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import os
import re
from socket import timeout as SocketTimeout
import logging


SCP_COMMAND = b'scp'
Expand Down Expand Up @@ -140,6 +141,7 @@ def __init__(self, transport, buff_size=16384, socket_timeout=10.0,
self.socket_timeout = socket_timeout
self.channel = None
self.preserve_times = False
self.recursive = False
if progress is not None and progress4 is not None:
raise TypeError("You may only set one of progress, progress4")
elif progress4 is not None:
Expand Down Expand Up @@ -270,6 +272,7 @@ def get(self, remote_path, local_path='',
asunicode(self._recv_dir))
rcsv = (b'', b' -r')[recursive]
prsv = (b'', b' -p')[preserve_times]
self.recursive = recursive
self.channel = self._open()
self._pushed = 0
self.channel.settimeout(self.socket_timeout)
Expand Down Expand Up @@ -428,11 +431,20 @@ def _recv_all(self):
msg = self.channel.recv(1024)
if not msg: # chan closed while receiving
break
assert msg[-1:] == b'\n'
msg = msg[:-1]

if msg[-1:] == b'\n':
msg = msg[:-1]
else:
continue

code = msg[0:1]
if code not in command:
raise SCPException(asunicode(msg[1:]))
if self.recursive:
self.channel._log(logging.ERROR, str(msg))
continue
else:
raise SCPException(asunicode(msg[1:]))

command[code](msg[1:])
# directory times can't be set until we're done writing files
self._set_dirtimes()
Expand Down