简体   繁体   中英

Copy files to a network path using python script

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.')

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM