Question

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?

Était-ce utile?

La solution

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)

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top