使用访问权限读取远程文件 [英] Read Remote File with Access Permissions

查看:134
本文介绍了使用访问权限读取远程文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从网络服务器(从Windows XP机器上)读取文件,我通常会通过询问 \\ServerName\dirPath\

现在,我必须编写一个程序,从服务器上读取文件,并在我的电脑上返回一些结果。

>

我面临的问题是,我的电脑上的登录名没有在服务器上的登录帐户。因此,当我尝试时我无法读取服务器上的文件:

  f = open(r'\ \server\path\to\file','r')

我知道我可以通过添加一个用户帐户到服务器或我的电脑来解决这个问题,但缺乏这些解决方案,有没有办法让我将登录凭据传递给服务器?

我在PC上运行Windows XP,并在服务器上运行一些Linux。



谢谢

解决方案

你说这是一个Samba共享 - 查看 PySmbClient 。这样,你可以做这样的事情:

  client = smbclient.SambaClient(server =servername,share =sharename ,
username =foo,password =bar,domain =baz)
f = smb.open('/ path / to / file')
data = f。 read()
f.close()

可以使用Alernatives,如 PySamba


I am trying to read a file on a network server (from a Windows XP machine), which I would normally access by asking for \\ServerName\dirPath\ in the run dialog.

Right now, I have to write a program that reads the file off the server and returns some results on my PC.

The problem that I'm facing is that the login name on my PC does not have a login account on the server. As a result, I am unable to read the file on the server when I tried:

f = open(r'\\server\path\to\file', 'r')

I know that I can fix this by adding a user account to the server or to my PC, but short of those solutions, is there a way for me to pass login credentials to the server?

I am running Windows XP on my PC and some flavor of Linux on the server

Thank you

解决方案

You say it's a Samba share - have a look at PySmbClient. That way, you can do something like this:

client = smbclient.SambaClient(server="servername", share="sharename",
    username="foo", password="bar", domain="baz")
f = smb.open('/path/to/file')
data = f.read()
f.close()

Alernatives are available, such as PySamba.

这篇关于使用访问权限读取远程文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆