commit f09eb974bb9ba2ec23823585637ef489927cb057 Author: kromskii2 Date: Mon Feb 19 13:58:36 2024 +0700 Initial commit diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..dfe0770 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,2 @@ +# Auto detect text files and perform LF normalization +* text=auto diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..de86604 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# Dependencies +.psci_modules +.spago +bower_components +node_modules + +# Generated files +.psci +output diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..44c36a5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 kromskii2 + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..adda36a --- /dev/null +++ b/README.md @@ -0,0 +1,2 @@ +# Kfale + Kfale diff --git a/main.py b/main.py new file mode 100644 index 0000000..b8ad63e --- /dev/null +++ b/main.py @@ -0,0 +1,68 @@ +import os +from ftplib import FTP +import configparser + +def read_config(): + config = configparser.ConfigParser() + config.read('config.ini') + folder_path = config['DEFAULT']['folder_path'] + return folder_path + +def write_config(folder_path): + config = configparser.ConfigParser() + config['DEFAULT'] = {'folder_path': folder_path} + with open('config.ini', 'w') as configfile: + config.write(configfile) + +def read_ftp_config(): + config = configparser.ConfigParser() + config.read('ftp.ini') + ftp_info = { + 'host': config['DEFAULT']['host'], + 'username': config['DEFAULT']['username'], + 'password': config['DEFAULT']['password'] + } + return ftp_info + +def write_ftp_config(host, username, password): + config = configparser.ConfigParser() + config['DEFAULT'] = {'host': host, 'username': username, 'password': password} + with open('ftp.ini', 'w') as configfile: + config.write(configfile) + +def upload_file_ftp(file_path, ftp_info): + with FTP(ftp_info['host']) as ftp: + ftp.login(ftp_info['username'], ftp_info['password']) + with open(file_path, 'rb') as file: + ftp.storbinary(f'STOR {os.path.basename(file_path)}', file) + +def main(): + folder_path = input("Введите путь к папке для взаимодействия со скриптом: ") + write_config(folder_path) + + host = input("Введите IP адрес FTP сервера: ") + username = input("Введите логин для FTP сервера: ") + password = input("Введите пароль для FTP сервера: ") + write_ftp_config(host, username, password) + + folder_path = read_config() + ftp_info = read_ftp_config() + + while True: + file_name = input("Введите имя файла для копирования на FTP сервер (или 'exit' для выхода): ") + if file_name.lower() == 'exit': + break + + file_path = os.path.join(folder_path, file_name) + + if os.path.exists(file_path): + upload_file_ftp(file_path, ftp_info) + print("Файл успешно загружен на FTP сервер.") + # После успешной загрузки файла на FTP сервер можно удалить оригинальный файл. + os.remove(file_path) + print("Оригинальный файл удален.") + else: + print("Файл не найден.") + +if __name__ == "__main__": + main()