2

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)
5
  • And what was the result? We can help you better if you tell us what went wrong. Commented Jan 8, 2010 at 12:10
  • here is the output : python: can't open file 'sshfs': [Errno 2] No such file or directory Commented Jan 8, 2010 at 12:12
  • Is the path correct? try which sshfs to find out in shell. Commented Jan 8, 2010 at 12:20
  • sshfs is in the correct path. Manually invoking sshfs mounts the remote-directory under local mount point. but don't about using python script ... Commented Jan 8, 2010 at 12:21
  • yes..got it sshfs installed with root permission and changing to root and executing above script worked :) ..thank you all Commented Jan 8, 2010 at 12:27

3 Answers 3

3

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

Sign up to request clarification or add additional context in comments.

Comments

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

Comments

0

You can pip install sshfs python library from pypi

pip install sshfs

Here is the link https://pypi.org/project/sshfs/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.