Для этого я использую контейнеры докеров и моделирую сервер. Имя серверного контейнера — avalon-smb
Я использую библиотеку smbprotocol. У меня возникли проблемы с удаленным созданием файла - возникает ошибка, хотя путь кажется правильным.
Я нахожу в Интернете так мало информации, поэтому надеюсь, что смогу найти помощь здесь!конец файла /etc/samba/smb.conf
Код: Выделить всё
[avalon-backup-file-upload]
path = /tmp
browsable = yes
read only = no
guest ok = yes
veto files = /.apdisk/.DS_Store/.TemporaryItems/.Trashes/desktop.ini/ehthumbs.db/Network Trash Folder/Temporary Items/Thumbs.db/
delete veto files = yes
valid users = avalon
вот функция, которая это обрабатывает:
Код: Выделить всё
def handle_smb_transfer(configuration_backup, full_path, filename, subtransaction_transfer, port, address):
# Handling SMB transfer
if port is None:
port = 445
dest_path = os.path.join(f"\\\\{address}\\{configuration_backup.directory_path}\\{filename}")
connection = Connection(uuid.uuid4(), address, port=int(port))
session = Session(connection, configuration_backup.server_account_login, configuration_backup.server_account_password)
tree = TreeConnect(session, f"\\\\{address}\\{configuration_backup.directory_path}")
connection.connect()
try:
session.connect()
tree.connect()
file_to_transfer = Open(tree, dest_path)
file_to_transfer.create(
ImpersonationLevel.Impersonation,
FilePipePrinterAccessMask.FILE_WRITE_DATA,
FileAttributes.FILE_ATTRIBUTE_NORMAL,
ShareAccess.FILE_SHARE_READ,
CreateDisposition.FILE_OVERWRITE_IF, # Overwrite if file exists
CreateOptions.FILE_NON_DIRECTORY_FILE # Ensure it's treated as a file
)
# Use "rb" to read a binary file
with open(full_path, "rb") as local_file:
while chunk := local_file.read(1024 * 1024): # 1 MB at a time
# Write the content of the local file to the remote file
file_to_transfer.write(chunk, 0)
subtransaction_transfer.add_message(Message("Transferred file to SMB server.", MessageLevel.SUCCESS))
subtransaction_transfer.close(SubTransactionStatus.SUCCESS)
file_to_transfer.close()
finally:
connection.disconnect()
Подробнее здесь: https://stackoverflow.com/questions/793 ... t-path-not
Мобильная версия