diff --git a/fsspec/asyn.py b/fsspec/asyn.py index efdac868b..c27df1c2f 100644 --- a/fsspec/asyn.py +++ b/fsspec/asyn.py @@ -369,12 +369,16 @@ async def _put(self, lpath, rpath, recursive=False, **kwargs): lpath = make_path_posix(lpath) fs = LocalFileSystem() lpaths = fs.expand_path(lpath, recursive=recursive) - rpaths = other_paths(lpaths, rpath) + dirs = [l for l in lpaths if os.path.isdir(l)] + rdirs = other_paths(dirs, rpath) + await asyncio.gather(*[self._makedirs(d, exist_ok=True) for d in rdirs]) + files = sorted(set(lpaths) - set(dirs)) + rpaths = other_paths(files, rpath) batch_size = kwargs.pop("batch_size", self.batch_size) return await _throttled_gather( [ self._put_file(lpath, rpath, **kwargs) - for lpath, rpath in zip(lpaths, rpaths) + for lpath, rpath in zip(files, rpaths) ], batch_size=batch_size, )