Python Forum
Failing to copy file from a network to a local drive - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Failing to copy file from a network to a local drive (/thread-32067.html)



Failing to copy file from a network to a local drive - tester_V - Jan-19-2021

Hi,
I'm trying to copy files from a network folder.
For some reason my code produces an error:
import os
import shutil

fname = 'somelog_file.txt'
p04 = 'D:\\JFLogs\\p04\\'  ## local folder ##
h04 = '\\\\FF04OBS0004\\c$\\dir\\subdir\\' 

fto_download = h04+fname
print (fto_download)
shutil.copy(fto_download, p04) 
Any help appreciated!
Thank you!


RE: Failing to copy file from a network to a local drive - Oshadha - Jan-19-2021

This
Error:
\\FF04OBS0004\c$\dir\subdir\somelog_file.txt Traceback (most recent call last): File "C:\Users\User\AppData\Local\Temp\atom_script_tempfiles\05d938a0-5a1f-11eb-857f-2dd3f1980bd4", line 19, in <module> shutil.copy(fto_download, p04) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\shutil.py", line 415, in copy copyfile(src, dst, follow_symlinks=follow_symlinks) File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\shutil.py", line 261, in copyfile with open(src, 'rb') as fsrc, open(dst, 'wb') as fdst: FileNotFoundError: [Errno 2] No such file or directory: '\\\\FF04OBS0004\\c$\\dir\\subdir\\somelog_file.txt'



RE: Failing to copy file from a network to a local drive - tester_V - Jan-19-2021

Yes! Smile
"No such file or directory...."
I can map the directory to my Server and I see the files and access etc...
I do not understand what I'm doing wrong Cry

What is it?
Thak you@


RE: Failing to copy file from a network to a local drive - tester_V - Jan-20-2021

Any ideas why I'm having this error?

Thank you.


RE: Failing to copy file from a network to a local drive - tester_V - Jan-20-2021

Just wanted to share,
Adding 'try' fixed the problem Cool

import os
import shutil
 
fname = 'somelog_file.txt'
p04 = 'D:\\JFLogs\\p04\\'  ## local folder ##
h04 = '\\\\FF04OBS0004\\c$\\dir\\subdir\\' 
 
fto_download = h04+fname
print (fto_download)
try:

    shutil.copy(fto_download, p04)
except Exception as e:
    print (e)
Thank you! Big Grin