Send file by HTTP post

Is it possible to send a file (around 400 KB) stored on ROS local filesystem via HTTP POST? If so, how?

This is an XY problem: you’re specifying the final form of the solution to your problem instead of posting the actual problem and letting the brain trust come up with solutions.

There are numerous ways to make another machine come back to the router and fetch the file from it instead of sending it out to the remote system. I could try to list them all, but knowing what the file is, why it’s created on the router, where it goes, and so forth would let me pare that down to a single recommended solution for that particular combination of criteria.

Or, maybe you do have a good cause to have the router push the file out, but another protocol would be better. Why must it be HTTP POST? You don’t say, which leads those trying to help to be suspicious that you’re posting here after making your hand sore trying to bang that screw in with a hammer.

I have RouterOS 7.1.3 and want to use /tool fetch to do HTTP POST upload of .rsc file to destination HTTP server.
Please advise - how to achieve this.
Thank you

Again I ask, why must it be HTTP POST? Why can’t it be the remote server doing HTTP GET on files stored on the router’s flash? Why can’t it be scp from the same direction? If it has to be done from the RouterOS side, then why can’t it be “/fetch mode=ftp upload…”?

because, i have multiple routers in multiple locations, and i want to do schedule script to create and send backup.
some routers are behind NAT so connection in other direction is not possible.
The only “server” that I have is HTTPS one, no FTP nor SSH/SCP in my case.
RouterOS supports http post and sending file, but it does not work in my case, can somebody help?

So schedule an SSH connection to call /export on them, as my backup system does.


some routers are behind NAT

So port-forward SSH out to where it can be reached, or use a VPN, or set all of them up on ZeroTier, or…

This forum is filled with solutions to that problem.


no FTP

It’s easily enabled on every server-class OS.

It’s not particularly secure, but if you do it over a VPN, it doesn’t matter.

Also, some FTP servers have a “dropbox” mode where files can be added but not downloaded again, which can be helpful in cases like this.


nor SSH/SCP in my case.

Also easily added, especially the client side as in my backup script.

I am using AWS Lambda and/or Azure Functions as the only server/service resources, they have application installed and configured that accepts HTTPS only requests receiving HTTP file upload.
No other OS, so no FTP again.
I do not want to use FTP etc.
No other options in my case and I am not interested in doing FTP etc..

Can you help me with single line of RouterOS /tool fetch to achieve HTTP POST file upload?

I have made a test:


:global $data "test";
:global $url "https://prod-51.westeurope.logic.azure.com:443/workflows/blabla/triggers/manual/paths/invoke....";
/tool fetch mode=https http-method=put http-data=$data url=$url

and this is recieved as, which seems kind of fine

{
    "headers": {
        "User-Agent": "Mikrotik/7.x,Fetch",
        "Content-Type": "application/x-www-form-urlencoded"
    },
    "body": {
        "$content-type": "application/x-www-form-urlencoded",
        "$content": "dGVzdA==",
        "$formdata": [
            {
                "key": "test",
                "value": ""
            }
        ]
    }
}

However, if I try to load file content into variable (file is about 7 KB)

/export file=export.rsc
:global data [/file get [/file find name=export.rsc] contents];

and after http fetch , there is no body data received on http server.

How to send a file content? also, for export and for backup files using HTTP ?

If sending file is not supported by /tool fetch via HTTP method, then this should be documented, and where I can create a feature request?

You have asked for the same i 3 post (for me that is SPAM). That is not needed, and it will not help you. Any request you like, send to support@mikrotik.com

I would like the answer also.
Dont want servers coming in to get files, want the router to push the file to the server.

If you dont know the answer, stop posting, stop telling him its a dumb approach. its not.

It doesn’t matter how bright your idea is if it comes down to a question between a working solution today versus weeks, months, or years spent griping about and agitating for the feature in the precise form you desire.

Time from first post to now: 2 months 10 days. Even if the desired feature popped up in a beta today, there must be those that are glad they didn’t spend that time waiting for their idealized form of the solution, but instead took good advice and went with something that would work during that span.

If we could wave a magic wand and get HTTP post file uploads with all the bells and whistles you want (e.g. X.509 client certs for authentication so randos can’t spam your upload server) I’m sure no one would be arguing.

Now go find me that magic wand. :slight_smile:

@tangent, It’s almost like spam on this topic. It’s always “+1 for HTTP file upload”, but it’s like no one talk where they were sending since what type of upload it support matters too.

At some point containers will let you do all these things, since you’d have access to curl.