从 Python 运行 Rsync

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18369136/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 10:34:39  来源:igfitidea点击:

Run Rsync from Python

pythoncurlrsync

提问by Marcus

I need to run an rsync command from Python. Is this possible and if so, how do I do it?

我需要从 Python 运行 rsync 命令。这可能吗,如果可以,我该怎么做?

rsync -Ccavz --delete DJStatic username@website

回答by philshem

You can call a subprocess from python using the following snippet

您可以使用以下代码段从 python 调用子进程

import subprocess
subprocess.call(["ls", "-l"])

In your case, it would be something like this

在你的情况下,它会是这样的

subprocess.call(["rsync", "-Ccavz", "--delete","DJStatic", "username@website"])

See herefor more details.

请参阅此处了解更多详情。