Reputation: 5444
I am trying to copy files from hard disk to a network path drive using python script. MY script is simple however it doesnt work since it seems that I need to add credentials in order to perftorm such action.
import glob, os
import shutil
myPath = "E://data//"
dst = "C://Users//user//networkPath//"
for file in os.listdir(myPath):
shutil.copy2(myPath+file, dst+file)
This works only for default system directories and not for a network path. What should I do in case of network path?
EDIT I am trying to do something like this:
win32wnet.WNetAddConnection2(0, None, '\\\\'+"http://ip:port/", "user", "pass") however I am getting the message:
pywintypes.error: (67, 'WNetAddConnection2', 'The network path was not found.')
Upvotes: 1
Views: 1815
Reputation: 382
import win32wnet
win32wnet.WNetAddConnection2(0, None, '\\\\'+host, None, username, password)
shutil.copy(source_file, '\\\\'+host+dest_share_path+'\\')'
win32wnet.WNetCancelConnection2('\\\\'+host, 0, 0)
Edit : Code Formatted
Upvotes: 3