@@ -1502,17 +1502,25 @@ def download_file(self, remote, local = None):
15021502 calling the function twice has little overhead.
15031503
15041504 Arguments:
1505- remote(str): The remote filename to download
1505+ remote(str/bytes ): The remote filename to download
15061506 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
15071518 """
15081519
15091520
15101521 if not local :
15111522 local = os .path .basename (os .path .normpath (remote ))
15121523
1513- if os .path .basename (remote ) == remote :
1514- remote = os .path .join (self .cwd , remote )
1515-
15161524 with self .progress ('Downloading %r to %r' % (remote , local )) as p :
15171525 local_tmp = self ._download_to_cache (remote , p )
15181526
@@ -1694,6 +1702,18 @@ def download(self, file_or_directory, local=None):
16941702 file_or_directory(str): Path to the file or directory to download.
16951703 local(str): Local path to store the data.
16961704 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
16971717 """
16981718 file_or_directory = packing ._encode (file_or_directory )
16991719 with self .system (b'test -d ' + sh_string (file_or_directory )) as io :
@@ -1769,7 +1789,7 @@ def interactive(self, shell=None):
17691789
17701790 if self .cwd != '.' :
17711791 cmd = 'cd ' + sh_string (self .cwd )
1772- s .sendline (cmd )
1792+ s .sendline (packing . _need_bytes ( cmd , 2 , 0x80 ) )
17731793
17741794 s .interactive ()
17751795 s .close ()
0 commit comments