Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
Fix broken paths with creating/uploading directories and files
Browse files Browse the repository at this point in the history
Previously, paths for uploading files and creating directories would have the relative path where the downloaded files from the FTP were stored. This behavior would cause an issue with uploads not being in the correct spot. This is now resolved.
  • Loading branch information
garrettsummerfi3ld committed Feb 1, 2023
1 parent 5da491c commit 6a63563
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,30 @@ def upload_files():
# Upload a file to the staging server using the Pterodactyl API
for root, dirs, files in os.walk("./files/default"):
for file in files:
rel_path = os.path.relpath(
os.path.join(root, file), "./files/default")
file_path = os.path.join(root, file)
rel_file_path = os.path.relpath(file_path, "./files/default")
if file.endswith(".zip"):
print("Skipping file: " + rel_path)
print("Skipping file: " + rel_file_path)
continue
else:
print("Uploading file: " + rel_path)
print("Uploading file: " + rel_file_path)
file_upload_url = api.client.servers.files.get_upload_file_url(
server)
file_upload_request = requests.post(
file_upload_url + "&directory=/" + rel_path.replace("\\", "/"),
files={'files': open('./files/default/' + rel_path, 'rb')})
file_upload_url + "&directory=/" + os.path.dirname(rel_file_path),
files={'files': open('./files/default/' + rel_file_path, 'rb')})
if file_upload_request.status_code == 200:
print("File uploaded: " + file)
print("File uploaded: " + rel_file_path)
else:
print("File upload failed: " + file)
print("File upload failed: " + rel_file_path)
print(file_upload_request.text)
for dir in dirs:
print("Creating directory: " + dir)
sub_dir = os.path.join(root, dir)
rel_sub_dir = os.path.relpath(sub_dir, "./files/default").replace("\\", "/")
print("Creating directory: " + rel_sub_dir)
api.client.servers.files.create_folder(
server, dir, "/" + os.path.relpath(os.path.join(root), "./files/default").replace("\\", "/"))
print("Directory created: " + dir)
server, rel_sub_dir, "/")
print("Directory created: " + rel_sub_dir)


def stop_server():
Expand Down

0 comments on commit 6a63563

Please sign in to comment.