Skip to content

Commit fa850c1

Browse files
authored
fix putting multiple files using SFTP (#1991)
Fixes #1990
1 parent e6668a1 commit fa850c1

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

fsspec/implementations/sftp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ def ls(self, path, detail=False):
135135
paths = [stat["name"] for stat in stats]
136136
return sorted(paths)
137137

138-
def put(self, lpath, rpath, callback=None, **kwargs):
139-
rpath = self._strip_protocol(rpath)
138+
def put_file(self, lpath, rpath, callback=None, **kwargs):
139+
self.mkdirs(self._parent(os.fspath(rpath)), exist_ok=True)
140140
logger.debug("Put file %s into %s", lpath, rpath)
141141
self.ftp.put(lpath, rpath)
142142

fsspec/implementations/tests/test_sftp.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,21 @@ def test_put_file(ssh, tmp_path, root_path):
147147

148148
f = fsspec.get_filesystem_class("sftp")(**ssh)
149149
f.put_file(lpath=tmp_file, rpath=root_path + "a.txt")
150+
assert f.exists(root_path + "a.txt")
151+
152+
153+
def test_put_many_files(ssh, tmp_path, root_path):
154+
tmp_file_a = tmp_path / "a.txt"
155+
with open(tmp_file_a, mode="w") as fd:
156+
fd.write("blabla")
157+
tmp_file_b = tmp_path / "b.txt"
158+
with open(tmp_file_b, mode="w") as fd:
159+
fd.write("blabla")
160+
161+
f = fsspec.get_filesystem_class("sftp")(**ssh)
162+
f.put(lpath=[tmp_file_a, tmp_file_b], rpath=root_path)
163+
assert f.exists(root_path + "a.txt")
164+
assert f.exists(root_path + "b.txt")
150165

151166

152167
def test_simple_with_tar(ssh, netloc, tmp_path, root_path):

0 commit comments

Comments
 (0)