Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open Windows shared folder through linux machine

Tags:

python

urllib

I am using python 2.5 on Ubuntu, and there's a machine in the same network called machine1. The folder is shared.

How to to get a file in a specific folder of that machine?

I have tried, with no success:

urllib.urlopen('\\machine1\folder\file.txt')
like image 695
bluefoot Avatar asked Mar 10 '10 19:03

bluefoot


People also ask

How do I mount a Windows shared folder in Linux?

The safest way to mount Windows-shared folders on Linux is to use the CIFS-utils package and mount the folder using the Linux terminal. This allows Linux machines to access SMB file shares used by Windows PCs. Once installed, you can then mount your Windows share folder from the Linux terminal.

Can I access Windows files from Linux?

WSL also allows you to run Linux command-line tools and apps alongside your Windows command-line, desktop and store apps, and to access your Windows files from within Linux. This enables you to use Windows apps and Linux command-line tools on the same set of files if you wish.

How do I access a network share in Linux?

Connect to a file serverIn the file manager, click Other Locations in the sidebar. In Connect to Server, enter the address of the server, in the form of a URL. Details on supported URLs are listed below. If you have connected to the server before, you can click on it in the Recent Servers list.


1 Answers

Linux has a utiliy called smbmount, which can be found in package smbutils I believe.

This is a command line utility which mounts a Windows share to a directory on the local machine, optionally with username/password.

smbmount is I believe a utility which runs as root, so whether it's suitable for you I don't know. Maybe it can be used as user.

You could either mount the share by default on the Linux machine, thereby accessing the files on it as local files, or you could do the smbmount / smbumount from within the python script with exec or something like that.

mkdir WindowsShare # Do this only once
smbmount \\server\share /home/me/WindowsShare -ousername=...,password=...
ls /home/me/WindowsShare
smbumount /home/me/WindowsShare

Username and password can be written in a file for some security. Check the man page.

If you need something totally python have a look at pysmb. Terms to google for are python, smb, CIFS.

like image 195
extraneon Avatar answered Oct 10 '22 00:10

extraneon