daaredevill
daaredevill

Reputation: 31

Copy content from local folder to remote folder in python

I am trying to copy files from a local folder to a remote windows share using python. So the main requirement is to move files from source folder (which keeps changing) to a Remote Share:

Not sure what I am doing wrong but below is what I have tried to so far:

# Move the archive file to DVD Burner Box
 destPath = '\\\\10.10.10.10\\DestFolder\\'
 destFolder = destPath + ('%s_%s\\') %(id1,id2)
 srcArchFolderPath = '.\\prepared\\%s_%s\\' %(id1,id2)
 srcArchFiles = os.listdir(srcArchFolderPath)

try:
    os.makedirs(destFolder)
except OSError:
    pass

shutil.copytree (srcArchFiles,destFolder,ignore=None)

The sourceFolderPath keeps changing on every run with different input.

Ex: it can be .\prepared\1_2 or .\prepared\2_3 which will keep changing on every script run.

If I print srcArchFiles it shows list of the folders which exists in srcArchFolderPath succesfully. Also os.makedirs(destFolder) creates a folder succesfully on the remote share location. But the files copy is failing and not sure why it's failing, I belive I am not doing something right with shutil.

Following is the error I am seeing: File "C:\Python26\lib\shutil.py", line 140, in copytree names = os.listdir(src) TypeError: coercing to Unicode: need string or buffer, list found

Any help in correcting this is much appreciated.

Upvotes: 1

Views: 2949

Answers (2)

anhldbk
anhldbk

Reputation: 4587

I've found a good solution here: Execute remote commands on windows like psexec (Python recipe)

Upvotes: 0

Matthias
Matthias

Reputation: 13232

srcArchFiles is a list of folders. shutil.copytree needs one folder as the first parameter.

You have to use a loop to copy each folder.

for foldername in srcArchFiles:
    shutil.copytree (foldername, destFolder, ignore=None)

Upvotes: 0

Related Questions