首页 > 解决方案 > python pysftp issue downloading directory from remote server

问题描述

sftp = pysftp.Connection(server, username=username, password=password)
if remotepath == "NOAA18":
  sftp.get_r("/home/pi/AltiWx/data/NOAA-18/", localpath, preserve_mtime=True)
elif remotepath == "NOAA15":
  sftp.get_r("/home/pi/AltiWx/data/NOAA-15/", localpath, preserve_mtime=True)
elif remotepath == "METEOR-M2":
  sftp.get_r("/home/pi/AltiWx/data/METEOR-M2/", localpath, preserve_mtime=True)
elif remotepath == "NOAA19":
  sftp.get_r("/home/pi/AltiWx/data/NOAA-19/", localpath, preserve_mtime=True)
elif remotepath == "ALL":
  sftp.get_r("/home/pi/AltiWx/data/", localpath, preserve_mtime=True)
elif remotepath == "userinput":
  userinput = remotepath
  sftp.get_r(userinput, localpath, preserve_mtime=True)

so this is my code, i am using yaml to load a config and then everything goes into place, these are some presets i made. but then i get this error:

File "C:\Users\paolo\Desktop\pull\pull.py", line 33, in <module>
   sftp.get_r("/home/pi/AltiWx/data/", localpath, preserve_mtime=True)
 File "C:\Users\paolo\AppData\Local\Programs\Python\Python39\lib\site-packages\pysftp\__init__.py", line 309, in get_r
   self.get(fname,
 File "C:\Users\paolo\AppData\Local\Programs\Python\Python39\lib\site-packages\pysftp\__init__.py", line 249, in get
   self._sftp.get(remotepath, localpath, callback=callback)
 File "C:\Users\paolo\AppData\Local\Programs\Python\Python39\lib\site-packages\paramiko\sftp_client.py", line 801, in get
   with open(localpath, "wb") as fl:
FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/paolo/Desktop\\./home/pi/AltiWx/data/ISS (ZARYA)/FM/20210720T214913Z/20210720T214913Z.wav'

i have no idea what to do tbh

标签: pythonsftppysftp

解决方案


推荐阅读