Sending a file from the server to yourself in Telegram

I am using Telegram for its intended purpose. But sometimes, relying on the cool capabilities of its Bot API, it is impossible to avoid making your life easier. Somehow, already in the blog, I wrote a post about backup scripts in Telegram, which we spin on small projects and have already specifically saved our lives and the lives of our projects several times.

I very often have to pull out some files from servers (my own and client’s) and transfer them further via telegrams. For example, test database dumps, docker-compose files, and more. For a long time I downloaded files via winscp and transferred them to telegrams to whoever needed. But when the file is large, it is inconvenient – while downloading, while uploading.

Little story below

With the client we bought an https certificate for his project and it was necessary to transfer a csr file from the server for its subsequent processing. The server is located behind vpn, it was inconvenient and lazy to go directly through WinSCP. And I decided to try to send the file via telegram to myself. It worked:)

Also, a couple of months ago, in this way I transferred the dump of the test database to a new developer and realized that the method was really working and started using it regularly. I even started writing a binary in Go at first, but halfway through I realized that the issue was solved with a simple 5-line BASH script using curl. The script itself can be seen below.

The script itself

For it to work, you need to specify your Bot Token and Chat Id, where to send the file itself. That’s all:)

Further, for convenience, you can make an alias

alias tgsender="/home/zvinger/tgsender.sh"

And you can send files with a simple command

tgsender filename.json

And the file will be in your personal account from your bot!