如何通过Python将文件从Raspberry Pi复制到NAS上?

问题描述 投票:0回答:1

我有一个相机模块连接到我的Raspberry Pi,并希望直接将图片保存在我的NAS上,我使用picamera库来控制相机。相机工作正常,我可以直接将图片保存在Pi上。我试过先将图片保存在Pi的本地,然后通过os.move或shutil.move来移动图片。我试过先将图片保存在我的Pi上的本地,然后通过os.move或shutil.move移动它们,但是没有成功。另外shutil.copy也不行。我可以通过python在NAS上创建.txt文件和文件夹,但复制文件却无法工作。

作为一个例子,我的代码看起来像。

tempPath = '/home/pi/Desktop/test.jpg' #local directory
destinationPath = '/home/pi/myNAS/test.jpg' #mounted NAS

camera = PiCamera()
camera.start_preview()
sleep(5)
camera.capture(tempPath)
camera.stop_preview()
shutil.move(tempPath,destinationPath)
python raspberry-pi copy nas
1个回答
0
投票

我在你的代码中没有看到任何shutil的导入。你是否导入了shutil模块?

import shutil

另外,当你执行代码时,你得到什么样的错误?

© www.soinside.com 2019 - 2024. All rights reserved.