- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试使用 Python 访问 Samba 服务器上的文件。我发现我需要为此使用 Samba 客户端,所以我开始使用 PySmbClient。尽管网上有很多关于如何做到这一点的例子,但我就是不想工作。见下文。
smb = smbclient.SambaClient(server="192.168.0.320", share="DATA", domain="WORKGROUP",username="admin", password="abc123")
f = smb.open('test.json', 'r')
这会产生以下错误:
OSError: [Errno 2] No such file or directory
跟踪如下:
Traceback (most recent call last):
File "create_dataset.py", line 35, in <module>
f = smb.open('serverSaver.txt', 'r')
File "/home/grant/Development/create_dataset/env/local/lib/python2.7/site-packages/smbclient.py", line 408, in open
f = _SambaFile(self, path, mode)
File "/home/grant/Development/create_dataset/env/local/lib/python2.7/site-packages/smbclient.py", line 448, in __init__
connection.download(remote_name, self._tmp_name)
File "/home/grant/Development/create_dataset/env/local/lib/python2.7/site-packages/smbclient.py", line 393, in download
result = self._runcmd('get', remote_path, local_path)
File "/home/grant/Development/create_dataset/env/local/lib/python2.7/site-packages/smbclient.py", line 184, in _runcmd
return self._raw_runcmd(fullcmd)
File "/home/grant/Development/create_dataset/env/local/lib/python2.7/site-packages/smbclient.py", line 168, in _raw_runcmd
stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
File "/usr/lib/python2.7/subprocess.py", line 711, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1343, in _execute_child
raise child_exception
我已经阅读并实现了许多“解决方案”,但到目前为止,没有任何一个对我有用。我可以通过我的文件管理器使用给定的凭据访问 Samba 服务器,所以我知道这些值应该没问题。我什至和我们的系统管理员谈过,他不知道哪里出了问题。
肯定不止我写的这么简单的代码。您认为服务器端有问题吗?有我输入到 SambaClient 中的值吗?在这一点上,我对任何能带来解决方案的事情都持开放态度。
最佳答案
下面是一些适用于我的代码,可将文件从 Linux Samba 共享传输到我的 Windows 笔记本电脑。众所周知,它在其他方向(Linux 客户端、Windows 服务器)也能正常工作。
我使用的是 pysmb 库版本 1.1.19(最新)和 Python 2.7.1。
参见 the pysmb site对于 pysmb 包;我实际上是直接从它的 tarball 和 setup.py 下载并安装它的,因为 pip 抛出了一个错误。
pysmb 包对用户不太友好,但它适用于 Windows 客户端。
我使用 smb.conf 中的以下条目在 Linux 机器上为用户“edwards”设置了一个名为“my_share”的共享:
[my_share]
path = /home/edwards
valid_users = edwards
read only = no
guest ok = yes
browseable = yes
然后使用以下代码列出共享上的文件,并将名为“rti_license.dat”的文件下载到我的笔记本电脑:
import tempfile
import smb
import shutil
from smb.SMBConnection import SMBConnection
share_name = "my_share"
user_name = "edwards"
password = "######" # secret :-)
local_machine_name = "laptop" # arbitrary
server_machine_name = "edwards-Yocto" # MUST match correctly
server_IP = "192.162.2.1" # as must this
# create and establish connection
conn = SMBConnection(user_name, password, local_machine_name, server_machine_name, use_ntlm_v2 = True)
assert conn.connect(server_IP, 139)
# print list of files at the root of the share
files = conn.listPath(share_name, "/")
for item in files:
print item.filename
# check if the file we want is there
sf = conn.getAttributes(share_name, "rti_license.dat")
print sf.file_size
print sf.filename
# create a temporary file for the transfer
file_obj = tempfile.NamedTemporaryFile(mode='w+t', delete=False)
file_name = file_obj.name
file_attributes, copysize = conn.retrieveFile(share_name, "rti_license.dat", file_obj)
print copysize
file_obj.close()
# copy temporary file
shutil.copy(file_name, "rti_license.dat")
# close connection
conn.close()
请注意,服务器名称必须正确,否则连接将无法正常工作(在 Linux 机器上,它是 hostname 命令的输出)
希望这可能有用。
关于python - 无法通过Python访问Samba服务器上的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45552239/
我想通过 samba 共享在我的 linux 机器上编辑 Solr 配置文件。这些文件需要是 tomcat6:mygroup,但是当我通过 Windows 编辑文件时,它会将它们写入 myuser:m
我在用于开发的 FreeBSD 机器上有一个 samba 网络共享。 我在我的 WinXP 机器上将其设置为共享驱动器,并且运行良好。 但是,如果我重新启动 xp 盒,共享驱动器将无法访问,直到我单击
但是,据最近一次,国外科技网站w3techs的数据显示,截止到2010年7月28日,CentOS以高达31.6%的份额占据了Linux Web服务器的榜首,第二和第三分别是Debian和Red Ha
我已经设置了一个我正在修补的新 linux 盒子。我一直设置的一项是 samba,以便我可以轻松地将文件复制到服务器或从服务器复制文件。 我提出这个话题的原因是我无法从我的 Windows 机器浏览到
我正在尝试使用 samba 将用户导入 samba-tool 。 我可以添加具有任意属性的用户,假设测试用户有电话、职位等。从 samba wiki 我找到了以下片段,其中包含一些自定义属性: :~$
我正在尝试实现一个远程文件系统并且正在考虑使用 libsmbclient 要做到这一点。不幸的是,我在 googleling for 时没有遇到任何有用的文档 它。任何人都可以建议我详细描述 libs
我必须卸载samba ,因为我配置错误。但现在当我尝试使用 sudo apt-get install samba smbfs 重新安装它时,我得到输出:- Reading package lists.
我已经在我的树莓派上安装了运行 debian (raspbian) 的 samba 和 samba-common-bin 然后我更改 samba 的配置并在末尾添加以下内容: [photocam] c
为了提高性能,是否可以在 Linux 上从 CIFS 挂载文件异步读取? 谢谢!!! 最佳答案 Glibc 的 aio 实现创建线程来执行 I/O,因此它不依赖于文件系统类型来工作。 (另一方面,这也
我目前正在使用 CentOS 6.5 并尝试通过 samba 共享来共享文件。另一台机器是 Windows 8 x64。我可以毫无问题地将文件夹从 Windows 传输到 CentOS,但是,当我尝试
我有一台带有以下文件夹的 Ubuntu 机器。 我正在使用 samba 服务器共享文件夹。 我有 3 个用户: 用户 1 = 完全访问权限 用户 2 = 访问文件夹音乐(只读) 用户 3 = 访问文件
CFSDN坚持开源创造价值,我们致力于搭建一个资源共享平台,让每一个IT人在这里找到属于你的精彩世界. 这篇CFSDN的博客文章SWAT—Samba WEB管理工具介绍由作者收集整理,如果你对这篇文章
我在两个 Linux 机器(Ubuntu Desktop 12.10 和 Ubuntu Server 12.04)之间设置了 Samba。出于某种原因,我无法写入我的 samba 共享。在我看来,我拥
我正在使用一台没有根访问权限的机器,并且想以随机访问模式访问 Samba 服务器上的文件。我知道我可以使用 smbclient 完整地传输文件,但文件非常大 (>1GB),我宁愿将它们视为我可以进行随
我有一个安装了 MS Office 的 Microsoft Server 2019 Standard。我还有一个 Linux 服务器,它共享每个用户的 ~/windows/登录时使用其 Windows
我目前正在运行全新安装的 CentOS 7(64 位)。除了通过 Samba 进行存储外,这台机器不用于任何用途。但是,由于某种奇怪的原因,我看不到让共享可以通过 Windows 写入。映射驱动器后,
我正在尝试运行以下代码: shaliya@achala:~$ sudo apt-get install samba Reading package lists... Done Building dep
我有一个用于 samba 客户端的 java 代码,它可以将文件从我的 unix 机器放到 windows 机器上。我需要检查目录是否存在,如果不存在,则创建目录,然后将文件放入该目录。我可以将文件放
我可以在没有身份验证的情况下毫无问题地在网络共享上映射驱动器。但是一旦我尝试使用用户名和密码进行身份验证,我就错过了一些东西。这是代码的当前工作示例,其中包含我不断收到的错误消息。 #!/usr/bi
我正在尝试在我的树莓派上设置一个 samba 服务器。 我安装了 samba 并对我在各种 YouTube 视频或博客文章中找到的 smb.conf 进行了一些修改。 $ testparm/etc/s
我是一名优秀的程序员,十分优秀!