リモートコンピュータからコピーできない理由についてのアイデアはありますか? 最初のスニペットが機能し、 'servername'にコピーできます。 2番目のスニペットで「No such file or directory」と表示されます。私は 'servername'から私のローカルコンピュータにコピーしたいときにエラーが発生します。リモートコンピュータにコピーできますが、Pythonを使用してコピーできません
これはどちらか動作しません2
UPDATE ...
def copyfrom():
source_path = "\\computername\c$\test"
dest_path= "C:\localtest"
file_name = "testfile.txt"
shutil.copyfile(os.path.join(source_path, file_name), os.path.join(dest_path, file_name))
UPDATEは、私はあなたがshutilを使用してリモートコンピュータからコピーすることができないことを読んでいます。誰でも私の選択肢が何であるかについてのアイデアはありますか?
私がなぜ反対が動作していない
import os
import shutil
import fileinput
import re
import sys # some of these use for other code in my program
source = os.listdir("C:/Users/jm/Desktop/PythonUpdate/")
destination = '//' + servername + r'/c$/test/'
for files in source:
if files.endswith("myname.config"):
try:
os.makedirs(destination, exist_ok=True)
shutil.copy(files,destination)
except:
copyerror()
os.system('cls' if os.name == 'nt' else 'clear')
array = []
with open("C:/Users/jm/Desktop/PythonUpdate/serverlist.txt", "r") as f:
for servername in f:
copyfiles(servername.strip())
...これを使用しているコンピュータのリストにコピーされましたか?
def copyfrom(servername):
# copy config from server
source = os.listdir('//' + servername + r'/c$/test') # directory where original configs are located
destination = 'C:/Users/jm/Desktop/PythonUpdate/' # destination server directory
for files in source:
if files.endswith("myname.config"):
try:
os.makedirs(destination, exist_ok=True)
shutil.copy(files,destination)
except:
copyerror()
readconfig(servername)
# begin here
os.system('cls' if os.name == 'nt' else 'clear')
array = []
with open("C:/Users/jm/Desktop/PythonUpdate/serverlist.txt", "r") as f:
for servername in f:
copyfrom(servername.strip())
あなたのコードはA)適切にインデントされていない、B)何かが見つからないと思います(少なくとも最初のスニペットでは)。修正してください。 –
何をしないのですか?間違いはありますか?エラーは何ですか? また、なぜあなたは2つの関数を持っているのですか?同じ目的を持つ関数を書くことができます。 –
最初のスニペットは残念ですインデントエラーは発生しません。私は "No such file or directory"と言うエラーが出ています。さらに読むと、シャットダウンを使ってリモートでファイルをコピーできないようです。リモートコンピュータにのみコピーできます。 – Prox