Cannot copy file from a remote machine using shutil

末鹿安然 提交于 2021-02-08 19:44:00

问题


I need to copy a file from a remote machine.

The code is something like this

import shutil

shutil.copyfile('//XXX.XXX.XXX.XXX/home/Shares Folder/file.txt','/home/file.txt')

the location of the file is a shared folder but everytime I run this it gives me this error

File "", line 1, in ?

File "usr/lib/python2.4/shutil.py", line 47, in copyfile

frsc = open (src,'rb')

IOError: [Errno 2] No such file or directory : '//XXX.XXX.XXX.XXX/home/Shares Folder/file.txt'

Please take note that I'm running this script in my current machine and the the file that I want to copy is in the remote machine. I am not sure if this detail's relevant, I'm saying anyway.

Im 100% sure that the file is there so I was wondering why it's giving me such error message.

Im using CentOS and python 2.4.3

any ideas?


回答1:


shutil doesn't support remote file copies. It's for local copies only. If both of your machines are UNIX-based, you can try and employ some modules for a transport that you have available (SSH/SFTP, rsync, whanot)




回答2:


You've also tagged with samba and shared-folders - if you're trying to copy via samba, you might want to look into pysmbc or a similar python samba library. http://pypi.python.org/pypi/pysmbc/ even has an example of opening and reading a file over samba - it's a short step to writing the contents out locally.



来源:https://stackoverflow.com/questions/13060455/cannot-copy-file-from-a-remote-machine-using-shutil

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!