开发者

how to invoke sshfs within python script?

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开发者_StackOverflow giis@giis.co.in:/home/giis /mnt" 
os.system(cmd)


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


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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜