-
Notifications
You must be signed in to change notification settings - Fork 0
/
ftp.py
90 lines (70 loc) · 2.68 KB
/
ftp.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python3
# -*- coding: utf_8 -*-
# ftp.py - FTP installation Python script.
# Copyright (C) 2023 Makonede
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
import tomllib
from ftplib import FTP
from pathlib import Path, PurePosixPath
from typing import TypedDict
TITLE_ID = '01007EF00011E000'
LAYEREDFS = PurePosixPath('atmosphere/contents')
RELEASE = Path('release') / LAYEREDFS
class Config(TypedDict):
ip_address: str
port: int
username: str
password: str
def upload_mod(ftp: FTP, path: Path=Path()) -> None:
for child in (RELEASE / path).iterdir():
if child.is_file():
with open(child, 'rb') as file:
print(f'Uploading {child.name}')
ftp.storbinary(f'STOR {child.name}', file)
elif child.is_dir():
directory = f'{child.name}'
print(f'Entering {directory}')
ftp.mkd(directory)
ftp.cwd(directory)
upload_mod(ftp, path / child)
if path != Path():
ftp.cwd('..')
def main() -> None:
with open(Path('config') / 'ftp.toml', 'rb') as toml:
config: Config = tomllib.load(toml) # type: ignore
address: str = config['ip_address']
port: int = config['port']
username: str = config['username']
password: str = config['password']
print('Connecting...')
with FTP(
address, username, password, source_address=(address, port)
) as ftp:
print(f'Connected to {address}:{port}')
ftp.cwd(f'{LAYEREDFS}')
# Check for Breath of the Wild LayeredFS
if any(d[0] == TITLE_ID for d in ftp.mlsd()):
# Check for files in Breath of the Wild LayeredFS
if any(d[0] not in '..' for d in ftp.mlsd(TITLE_ID)):
overwrite = input('Mods are installed, overwrite? (y/n) ')
if not overwrite or overwrite[0] != 'y':
return
# Remove Breath of the Wild LayeredFS
ftp.rmd(TITLE_ID)
# Upload Link Cannon
upload_mod(ftp)
print('\nLink Cannon was installed successfully.')
if __name__ == '__main__':
main()