로컬 컴퓨터에서 FTP 서버로 파일을 복사하는 스크립트를 만들었습니다. 이 링크를 사용하여 스크립트 Upload folders from local system to FTP using Python script을 만들었지 만, 지금은 파이썬 스크립트를 사용하여 FTP에서 다른 위치의 다른 원격 컴퓨터로 파일을 복사하려고합니다. 이 작업을 수행하는 방법?FTP 서버에서 다른 FTP 서버로 파일을 복사하는 방법 (플랫폼 독립적)
파일 복사는 rsync
명령을 사용하여 수행 할 수 있지만 파이썬 스크립트를 사용하여이 작업을 수행하려고합니다.
코드 : FTP 프로토콜을 사용하면 컴퓨터에 액세스 할 수있는 유일한 방법 인 경우 일반적으로
import ftplib
import os
server = 'host'
username = 'name'
password = 'pass'
ftp = ftplib.FTP(server, username, password)
Path = 'path'#source
val = "/des/"#destination
def copy(source,destination):
print(source)
print(destination)
os.chdir(source)
ftp.cwd(destination)
if "C:\\" in Path or "c:\\" in Path:
ftp_path = (source).split("\\")[-1]
else:
ftp_path = (source).split("/")[-1]
directory = destination+ftp_path
mkdir(directory)
ftp.cwd(directory)
read = os.listdir(source)
for file in read:
print(file)
if "C:\\" in Path or "c:\\" in Path:
Type = source + "\\" + file
else:
Type = source + "/" + file
print(Type)
print()
if os.path.isdir(Type):#If Type is Folder then it will create new
folder
copy(Type,directory+"/")
elif os.path.isfile(Type):#If Type is file then it will create file
print(Type)
current_dir = ftp.pwd() + "/"
f = Type
fh = open(f, 'rb')
ftp.storbinary('STOR %s' % current_dir + file, fh)
fh.close()
def mkdir(path):
#print(path)
ftp.mkd(path)
copy(Path,val)
ftp.close()
질문은 이미 답이 여기있다 : https://stackoverflow.com/questions/11573817/how-to-download-a-file-via-ftp-with-python-ftplib#11573946이 trivilal에 대한 검색 더 질문. 추신. 이 스크립트에는 다른 GUI가 없습니다. –
내 GUI에있는 파일을 복사하기 위해 스크립트를 사용했습니다. 잠시만 기다려주십시오. 내 코드를 보여 드리겠습니다. –
* "원격 시스템"*의 의미는 무엇입니까? –