@@ -1502,17 +1502,25 @@ def download_file(self, remote, local = None):
1502
1502
calling the function twice has little overhead.
1503
1503
1504
1504
Arguments:
1505
- remote(str): The remote filename to download
1505
+ remote(str/bytes ): The remote filename to download
1506
1506
local(str): The local filename to save it to. Default is to infer it from the remote filename.
1507
+
1508
+ Examples:
1509
+ >>> with open('/tmp/foobar','w+') as f:
1510
+ ... _ = f.write('Hello, world')
1511
+ >>> s = ssh(host='example.pwnme',
1512
+ ... cache=False)
1513
+ >>> _ = s.set_working_directory(wd='/tmp')
1514
+ >>> _ = s.download_file('foobar', 'barfoo')
1515
+ >>> with open('barfoo','r') as f:
1516
+ ... print(f.read())
1517
+ Hello, world
1507
1518
"""
1508
1519
1509
1520
1510
1521
if not local :
1511
1522
local = os .path .basename (os .path .normpath (remote ))
1512
1523
1513
- if os .path .basename (remote ) == remote :
1514
- remote = os .path .join (self .cwd , remote )
1515
-
1516
1524
with self .progress ('Downloading %r to %r' % (remote , local )) as p :
1517
1525
local_tmp = self ._download_to_cache (remote , p )
1518
1526
@@ -1694,6 +1702,18 @@ def download(self, file_or_directory, local=None):
1694
1702
file_or_directory(str): Path to the file or directory to download.
1695
1703
local(str): Local path to store the data.
1696
1704
By default, uses the current directory.
1705
+
1706
+
1707
+ Examples:
1708
+ >>> with open('/tmp/foobar','w+') as f:
1709
+ ... _ = f.write('Hello, world')
1710
+ >>> s = ssh(host='example.pwnme',
1711
+ ... cache=False)
1712
+ >>> _ = s.set_working_directory('/tmp')
1713
+ >>> _ = s.download('foobar', 'barfoo')
1714
+ >>> with open('barfoo','r') as f:
1715
+ ... print(f.read())
1716
+ Hello, world
1697
1717
"""
1698
1718
file_or_directory = packing ._encode (file_or_directory )
1699
1719
with self .system (b'test -d ' + sh_string (file_or_directory )) as io :
@@ -1769,7 +1789,7 @@ def interactive(self, shell=None):
1769
1789
1770
1790
if self .cwd != '.' :
1771
1791
cmd = 'cd ' + sh_string (self .cwd )
1772
- s .sendline (cmd )
1792
+ s .sendline (packing . _need_bytes ( cmd , 2 , 0x80 ) )
1773
1793
1774
1794
s .interactive ()
1775
1795
s .close ()
0 commit comments