Arkadaşlar python ile nasıl file transfer yapabilirim? Örnek bir kod yazar mısınız? (client-server ilişkisi ile socket bağlantısı ile) mesela asd.exe yi çekeceğim veya karşıya yükleyeceğim. Gibi gibi
Follow along with the video below to see how to install our site as a web app on your home screen.
Not: This feature may not be available in some browsers.
#server.py
import socket
# Sunucu soketini oluşturma
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_address = ('localhost', 12345) # Sunucu adresi ve port numarası
server_socket.bind(server_address)
# Bağlantıları dinleme
server_socket.listen(1)
print("Sunucu başlatıldı. İstemci bekleniyor...")
while True:
# İstemci bağlantısı kabul etme
client_socket, client_address = server_socket.accept()
print("Bağlanan istemci:", client_address)
try:
# Dosya adını al
file_name = client_socket.recv(1024).decode()
print("İstenen dosya:", file_name)
# Dosyayı aç ve verileri oku
with open(file_name, 'rb') as file:
file_data = file.read()
# Dosyayı istemciye gönder
client_socket.sendall(file_data)
print("Dosya başarıyla gönderildi.")
finally:
# Bağlantıları kapat
client_socket.close()
#client.py
import socket
# Sunucu adresi ve port numarası
server_address = ('localhost', 12345)
# İstemci soketini oluşturma
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Sunucuya bağlanma
client_socket.connect(server_address)
try:
# Dosya adını gönder
file_name = "asd.exe" # İndirilecek dosyanın adı
client_socket.sendall(file_name.encode())
# Dosyayı sunucudan al
file_data = b''
while True:
data = client_socket.recv(1024)
if not data:
break
file_data += data
# Dosyayı yerel olarak kaydet
with open(file_name, 'wb') as file:
file.write(file_data)
print("Dosya başarıyla indirildi.")
finally:
# Bağlantıyı kapat
client_socket.close()
discord webhook ile yapabilirsin daha kolay olurArkadaşlar python ile nasıl file transfer yapabilirim? Örnek bir kod yazar mısınız? (client-server ilişkisi ile socket bağlantısı ile) mesela asd.exe yi çekeceğim veya karşıya yükleyeceğim. Gibi gibi
Peki örnek bir kod yazabilir misin?discord webhook ile yapabilirsin daha kolay olur
import requests
webhook_url = 'https://discord.com/api/webhooks/your_webhook_id/your_webhook_token'
file_name = 'carlon.exe'
with open(file_name, 'rb') as f:
file_data = f.read()
files = {'file': (file_name, file_data)}
response = requests.post(webhook_url, files=files)
if response.status_code == 200:
print("Dosya başarıyla gitti dayı")
else:
print("Dosya paylaşılırken bir hata oluştu :(. Hata kodu:", response.status_code)