Community discussions

MikroTik App
 
heavenlyangel
just joined
Topic Author
Posts: 18
Joined: Fri Apr 16, 2021 5:48 pm

Send file by HTTP post

Sat Feb 19, 2022 2:16 am

Is it possible to send a file (around 400 KB) stored on ROS local filesystem via HTTP POST? If so, how?
 
tangent
Forum Guru
Forum Guru
Posts: 1351
Joined: Thu Jul 01, 2021 3:15 pm
Contact:

Re: Send file by HTTP post

Sat Feb 19, 2022 3:00 am

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.
 
hkusulja
Frequent Visitor
Frequent Visitor
Posts: 75
Joined: Fri Apr 13, 2012 1:14 am

Re: Send file by HTTP post

Mon Feb 21, 2022 8:05 pm

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
Last edited by hkusulja on Tue Feb 22, 2022 8:10 am, edited 1 time in total.
 
tangent
Forum Guru
Forum Guru
Posts: 1351
Joined: Thu Jul 01, 2021 3:15 pm
Contact:

Re: Send file by HTTP post

Tue Feb 22, 2022 3:33 am

I have RouterOS 7.1.3 and want to use /tool fetch to to HTTP POST upload of .rsc file to destination HTTP server.

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..."?
 
hkusulja
Frequent Visitor
Frequent Visitor
Posts: 75
Joined: Fri Apr 13, 2012 1:14 am

Re: Send file by HTTP post

Tue Feb 22, 2022 8:11 am

I have RouterOS 7.1.3 and want to use /tool fetch to to HTTP POST upload of .rsc file to destination HTTP server.

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?
 
tangent
Forum Guru
Forum Guru
Posts: 1351
Joined: Thu Jul 01, 2021 3:15 pm
Contact:

Re: Send file by HTTP post

Tue Feb 22, 2022 8:26 am

i want to do schedule script to create and send backup.

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.
 
hkusulja
Frequent Visitor
Frequent Visitor
Posts: 75
Joined: Fri Apr 13, 2012 1:14 am

Re: Send file by HTTP post

Tue Feb 22, 2022 8:30 am

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?
 
hkusulja
Frequent Visitor
Frequent Visitor
Posts: 75
Joined: Fri Apr 13, 2012 1:14 am

Re: Send file by HTTP post

Fri Feb 25, 2022 10:17 am

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 ?
 
hkusulja
Frequent Visitor
Frequent Visitor
Posts: 75
Joined: Fri Apr 13, 2012 1:14 am

Re: Send file by HTTP post

Thu Mar 10, 2022 6:31 pm

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?
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3291
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Send file by HTTP post

Fri Mar 11, 2022 10:27 am

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
 
texmeshtexas
Member Candidate
Member Candidate
Posts: 151
Joined: Sat Oct 11, 2008 11:17 pm

Re: Send file by HTTP post

Fri Apr 29, 2022 1:55 am

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.
 
tangent
Forum Guru
Forum Guru
Posts: 1351
Joined: Thu Jul 01, 2021 3:15 pm
Contact:

Re: Send file by HTTP post

Fri Apr 29, 2022 2:54 am

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. :)
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3253
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Send file by HTTP post

Fri Apr 29, 2022 5:48 am

If you dont know the answer, stop posting, stop telling him its a dumb approach. its not.
Now go find me that magic wand. :)
@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.

Who is online

Users browsing this forum: doridian, druidgtx and 15 guests