如何在python脚本中调用sshfs?

发布于 2024-08-17 04:41:23 字数 317 浏览 2 评论 0原文

我想使用 sshfs 挂载远程目录。 sshfs 从终端工作正常。 但是如何从 python 脚本中调用它呢?

我尝试过类似的事情 - 但根本不起作用。

import os

cmd = "/usr/bin/sshfs [email protected]:/home/giis /mnt" 
os.system(cmd)

I want to mount a remote directory using sshfs. sshfs working fine from terminal.
But how to invoke it from within python script?

I tried something like this - but didn't work at all.

import os

cmd = "/usr/bin/sshfs [email protected]:/home/giis /mnt" 
os.system(cmd)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

愿与i 2024-08-24 04:41:23

首先,您应该确保您的 sshfs 命令使用 shell 可以正常工作。然后,转到此处查看许多使用Python的subprocess模块​​调用sshfs命令的示例

first, you should make sure your sshfs command works fine using the shell. Then, go to here to see many examples of using subprocess module of Python to call your sshfs commmand

不即不离 2024-08-24 04:41:23
import subprocess
mount_command = f'sshfs {host_username}@{host_ip}:{host_data_directory} {local_data_directory}'
subprocess.call(mount_command, shell=True)
# Do your stuff with mounted folder
unmount_command = f'fusermount -u  {local_data_directory}'
subprocess.call(unmount_command, shell=True)
import subprocess
mount_command = f'sshfs {host_username}@{host_ip}:{host_data_directory} {local_data_directory}'
subprocess.call(mount_command, shell=True)
# Do your stuff with mounted folder
unmount_command = f'fusermount -u  {local_data_directory}'
subprocess.call(unmount_command, shell=True)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文