Skip to content

Commit c397626

Browse files
authored
Fix bug at ssh.py:get() with relative path (#2214)
* Fix bug at ssh.py:get() with relative path * Add doctest for bug at ssh.py:get() * doctest for download and download_file * remove os.path.join, since _download_raw already seem handle remote paths * Add #2214 to stable changelog * Fix Doctest for ssh.py to not be dependent on user dir * Update CHANGELOG.md
1 parent 9f072e3 commit c397626

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,13 @@ The table below shows which release corresponds to each branch, and what date th
8484
[2186]: https://github.com/Gallopsled/pwntools/pull/2186
8585
[2129]: https://github.com/Gallopsled/pwntools/pull/2129
8686

87-
## 4.10.0 (`stable`)
87+
## 4.10.1 (`stable`)
88+
89+
- [#2214][2214] Fix bug at ssh.py:`download` and `download_file` with relative paths
90+
91+
[2214]: https://github.com/Gallopsled/pwntools/pull/2214
92+
93+
## 4.10.0
8894

8995
In memoriam — [Zach Riggle][zach] — long time contributor and maintainer of Pwntools.
9096

pwnlib/tubes/ssh.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,17 +1509,25 @@ def download_file(self, remote, local = None):
15091509
calling the function twice has little overhead.
15101510
15111511
Arguments:
1512-
remote(str): The remote filename to download
1512+
remote(str/bytes): The remote filename to download
15131513
local(str): The local filename to save it to. Default is to infer it from the remote filename.
1514+
1515+
Examples:
1516+
>>> with open('/tmp/foobar','w+') as f:
1517+
... _ = f.write('Hello, world')
1518+
>>> s = ssh(host='example.pwnme',
1519+
... cache=False)
1520+
>>> _ = s.set_working_directory(wd='/tmp')
1521+
>>> _ = s.download_file('foobar', 'barfoo')
1522+
>>> with open('barfoo','r') as f:
1523+
... print(f.read())
1524+
Hello, world
15141525
"""
15151526

15161527

15171528
if not local:
15181529
local = os.path.basename(os.path.normpath(remote))
15191530

1520-
if os.path.basename(remote) == remote:
1521-
remote = os.path.join(self.cwd, remote)
1522-
15231531
with self.progress('Downloading %r to %r' % (remote, local)) as p:
15241532
local_tmp = self._download_to_cache(remote, p)
15251533

@@ -1691,6 +1699,18 @@ def download(self, file_or_directory, local=None):
16911699
file_or_directory(str): Path to the file or directory to download.
16921700
local(str): Local path to store the data.
16931701
By default, uses the current directory.
1702+
1703+
1704+
Examples:
1705+
>>> with open('/tmp/foobar','w+') as f:
1706+
... _ = f.write('Hello, world')
1707+
>>> s = ssh(host='example.pwnme',
1708+
... cache=False)
1709+
>>> _ = s.set_working_directory('/tmp')
1710+
>>> _ = s.download('foobar', 'barfoo')
1711+
>>> with open('barfoo','r') as f:
1712+
... print(f.read())
1713+
Hello, world
16941714
"""
16951715
file_or_directory = packing._encode(file_or_directory)
16961716
with self.system(b'test -d ' + sh_string(file_or_directory)) as io:

0 commit comments

Comments
 (0)