主页 > 中文 > 新闻中心 >

新闻中心

Linux文件自动同步至Telegram的实现方案

流量次数: 作者:tg纸飞机 发布时间:2025-08-26 20:25

import requests

from watchdog.observers import Observer

from watchdog.events import FileSystemEventHandler

BOT_TOKEN = "YOUR_BOT_TOKEN

CHAT_ID = "YOUR_CHAT_ID

class UploadHandler(FileSystemEventHandler):

def on_created(self, event):

if not event.is_directory:

self.upload_file(event.src_path)

def upload_file(self, file_path):

url = f"

with open(file_path, 'rb') as f:

files = {'document': f}

data = {'chat_id': CHAT_ID}

requests.post(url, files=files, data=data)

observer = Observer

observer.schedule(UploadHandler, path='/path/to/watch')

observer.start

上一篇:Telegram手机版下载推荐最佳软件合集

下一篇:没有了