Initial commit

This commit is contained in:
kromskii2 committed 2024-02-19 14:05:25 +07:00
commit f09eb974bb
5 files changed
+102

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
+9
View File
@@ -0,0 +1,9 @@
# Dependencies
.psci_modules
.spago
bower_components
node_modules
# Generated files
.psci
output
+21
View File
@@ -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.
+2
View File
@@ -0,0 +1,2 @@
# Kfale
Kfale
+68
View File
@@ -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()