Skip to content

Commit 79dbdcd

Browse files
SFTPFile methods that override the AbstractFilesystem methods now strip protocol from path (#1940)
Co-authored-by: Martin Durant <[email protected]>
1 parent 11eabae commit 79dbdcd

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

fsspec/implementations/sftp.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ def _get_kwargs_from_urls(urlpath):
6666
return out
6767

6868
def mkdir(self, path, create_parents=True, mode=511):
69+
path = self._strip_protocol(path)
6970
logger.debug("Creating folder %s", path)
7071
if self.exists(path):
7172
raise FileExistsError(f"File exists: {path}")
@@ -89,10 +90,12 @@ def makedirs(self, path, exist_ok=False, mode=511):
8990
self.ftp.mkdir(new_path, mode)
9091

9192
def rmdir(self, path):
93+
path = self._strip_protocol(path)
9294
logger.debug("Removing folder %s", path)
9395
self.ftp.rmdir(path)
9496

9597
def info(self, path):
98+
path = self._strip_protocol(path)
9699
stat = self._decode_stat(self.ftp.stat(path))
97100
stat["name"] = path
98101
return stat
@@ -123,6 +126,7 @@ def _decode_stat(stat, parent_path=None):
123126
return out
124127

125128
def ls(self, path, detail=False):
129+
path = self._strip_protocol(path)
126130
logger.debug("Listing folder %s", path)
127131
stats = [self._decode_stat(stat, path) for stat in self.ftp.listdir_iter(path)]
128132
if detail:
@@ -132,6 +136,7 @@ def ls(self, path, detail=False):
132136
return sorted(paths)
133137

134138
def put(self, lpath, rpath, callback=None, **kwargs):
139+
rpath = self._strip_protocol(rpath)
135140
logger.debug("Put file %s into %s", lpath, rpath)
136141
self.ftp.put(lpath, rpath)
137142

@@ -168,6 +173,8 @@ def _rm(self, path):
168173
self.ftp.remove(path)
169174

170175
def mv(self, old, new):
176+
new = self._strip_protocol(new)
177+
old = self._strip_protocol(old)
171178
logger.debug("Renaming %s into %s", old, new)
172179
self.ftp.posix_rename(old, new)
173180

0 commit comments

Comments
 (0)