Fazer request via FTP e retornar arquivo via HTTP

Estou desenvolvendo um blog e gostaria de utilizar recursos de um outro servidor via FTP. Afim de compartilhar alguns desses arquivos em minhas postagens imaginei que seria possível eu conectar o FTP dentro do PHP e retornar o arquivo desejado para o usuário, sem que precisasse copiar para o meu servidor PHP do blog. Daí vem as perguntas: o PHP precisaria baixar todo o arquivo antes de retorna-lo? Que método eu deveria usar da biblioteca nicolab/php-ftp-client para conseguir tal efeito?

Um exemplo mais ou menos do que penso que seria:

Route::get('files/{id_artigo}/{arquivo}', 'FTPController@pegarArquivo'); 

E dentro do método, essa seria a parte interessante, porém não sei como prosseguir:

$  ftp = FTPClient(); $  ftp->connect($  host); $  ftp->login($  user, $  passwd); // Abaixo o dummyMethod() deveria // pegar o arquivo e armazenar em $  file // NOTA: $  nome é o nome do arquivo  $  file = $  ftp->dummyMethod($  nome); return $  file; 

Performing GET request with axios and displaying data to HTML [on hold]

I’m trying to use axios to perform a GET request on XML data. I’ve tried toying with different things and by moving stuff around, so I thought ask to get another pair of eyes. Here’s my code:


function loadDATA() {         axios.all([             axios.get(_[redacted].siteAbsoluteUrl + "/[]/_api/web/lists/getbytitle('[redacted]')/items?$  top=10&$  select=Title", {                  method: "GET",                 credentials: "include",                 mode: "no-cors",                 headers: {                     "Accept": "application/json; odata=verbose"                 }                        }),             axios.get(_[redacted].siteAbsoluteUrl + "/[]/_api/web/lists/getbytitle('[redacted]')/items?$  top=10&$  select=ResourceType", {                 method: "GET",                 credentials: "include",                 mode: "no-cors",                 headers: {                     "Accept": "application/json; odata=verbose"                 }                        })         ]).then(axios.spread((resources, titles) => {                 allResources = resources.data.d;                 docTitles = titles.data.d;             }));                } 

I’m pretty sure something goes here (below loadJSON()) to link the .js file with index.html, but I’m not sure what (document.querySelector(#middle-id)?. The info that I’ve looked up online seems to be pretty clear on the axios.get syntax but vague on the actual rendering.


<script type="text/javascript" src="scripts/getListItems.js"></script>  </head>      <div class="col-md-3" id="middle-id">                 <h3>All Documents</h3>             </div>  </body>  <script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.17.0/axios.js"></script> 

Finally, in my console I’m getting a message saying Expected ';' in regards to this line: loadJSON() {. Any thoughts about this one? I added a ; to the end of the code block but it didn’t change anything.

Reference request: Numerical methods for Hamilton-Jacobi-Bellman equations with state constraints

I have two questions on numerical methods for solving Hamilton-Jacobi-Bellman (HJB) equations with state constraints.

  1. Consider an optimal control problem given by $ $ v(x) = \max_{\{u(t)\}_t} \int_o^\infty e^{-\rho t}r(x(t), u(t))\, dt, \quad x(0) = x, $ $ subject to the law of motion $ $ \dot x = f(x(t),u(t))$ $ and the state constraint $ $ g(x) \ge 0. \tag1$ $ The HJB equation associated with this problem is given by $ $ \rho v(x)= \max_{u} r(x,u) + \nabla v(x) \cdot f(x,u),\tag2 $ $ where the state constraint (1) is imposed by requiring that $ v$ is subsolution of (2) at the boundary points $ \bar x \in \{x : g(x)=0\}$ .

The types of problems I am working on are typically solved numerically by the so called “upwind scheme” using finite difference methods. My question is, how to incorporate the state constraint $ g(x) \ge 0$ in these (or some other) numerical schemes. I have seen some papers considering one state and one control variable, but the methods in these papers seem to be quite 1-dimensional; I would need to handle a slightly more general case with two states and two controls. Thus, I am looking for a clear and comprehensive reference for the numerical (finite difference) methods handling this problem.

  1. To make the problem slightly more interesting, consider a sort of free boundary problem, where (1) is replaced by a more general constraint $ g(x,u)\ge 0$ depending also on the control variable $ u$ . Is there any theory for such problems (existence, uniqueness), and how about numerical methods for solving the problem? What would be the reference?

This question arises from macroeconomic models of the housing market, when imposing loan-to-value (LTV) collateral constraint of type $ B \le \theta PH$ , where $ B$ denotes the household debt, $ H$ denotes the amount of housing, $ \theta$ is a parameter describing maximal LTV ratio and $ P=P(H, u)$ is the (endogenously determined) price of housing, given the state $ x=(H,B)$ ; here $ $ g(x,u) = \theta PH-B.$ $

Correct regex expression for the location block inorder to capture CSS and JS when the request URL changes

I have developed nginx config file order to cater some custom error pages. I have created two location blocks to capture the main index.html file and other location to capture the css/js and the images. I have created the cs and the js files seperately and called into the main index file due to the ease of use. But this work only for the following types of url

https://example.com https://example.com/abcd/ 

But if the url cahnges to

https://exmaple.com/abcd/efgd/ or more the css and js won’t be in the response. The css/js and images are in a directory named techops-page-resources. So after checking bit on the issue I found that on the first two url it’ll get https://exmaple.com/resources as expected when the given domain is not available. But on the other occasions it’ll transformed into https://example.com/abcd/resources/ and this uri doesn’t exist. So I’ve tried different regex patterns and none of them seem to work. The following are the location blocks that I have implemented to set the error pages up.

error_page 503 /pages/maintenance.html; error_page 502 /pages/50x.html; error_page 404 /pages/40x.html;  location /pages/ {    root /var/www/html/ErrorPages/; }  location /techops-page-resources {      alias /var/www/html/ErrorPages/pages/techops-page-resources/; }  } 

What I expecting is whenever the 404 error returns I want the main index file to call the techops-page-resources and include them in the the final customized 404 error page as expected. But currently what I only receive is the basic index.html file which is in the pages directory. Is there a correct regex pattern to match only the techops-page-resource as a postfix match as follows

location **some_regex_pattern**/techops-page-resources {      alias /var/www/html/ErrorPages/pages/techops-page-resources/; } 

I would love to do this in this same architecture without using inline css or js

Handling multiple request at the same time on same resource [on hold]

I got some new case for me so there is an item A in database that has a quantity 1 and we got 2 user that want to checkout 1 Item A at the same time. How should the API response for these type of multiple request should we handling one of them and what is the approach for handling multiple request like this ??

How do I know that the request and response is using encryption protocols in burp suite?

I know these things can easily be done on wireshark, tshark, etc but is it possible to know that the request I forwarded and the response I received is using protocols such as TLS, TLSv1.2, TCP, HTTP, etc in Burp Suite? So I won’t have to switch to other network applications to see the protocols

Sample Request

POST /api/v2/app/login?optionalKeys=Yes HTTP/1.1  Accept: application/json; charset=utf-8 app-version: 2.3.12 version-code: 321 Tid: 21bb65df-0682-4085-8775-68e70f5653db sid: dn6e4e7c-d956-4b3e-956b-9c6b9634ef39 os-version: 5.1 deviceId: a62fb2d91cb17587 swuid: a62fb2d91cb17587 User-Agent: Android Connection: close Accept-Encoding: gzip, deflate latitude: 12.904043 longitude: 77.642919 X-NETWORK-QUALITY: GOOD Content-Type: application/json; charset=UTF-8 Content-Length: 48 Host: xyz.abc.com X-NewRelic-ID: UwUAVV5VGwIEXVJRAwcO  {"mobile":"1234567890","password":"Yt!*3773@8ATQwEr"} 

I don’t see any protocol mentioned

Google speech to text failing for async long audio request [on hold]

I am using Google speech to text API for online audio responses received through my application. I started running into issues recently when I have audio longer than 2 minutes. When I looked into it, I found that if we dont speak anything during the recording for over 2 minutes, then the long running recognize returns a timeout with a None value.

I get this error: Unexpected state: Long-running operation had neither response nor error set.

Not sure if this is a known issue. If so, are there plans to fix this and if there are any workarounds? What if someones decides to record after 2 mins of inactivity?

Can you add to a Github pull request after the source repo is deleted?

I’ve opened a pull request (PR) on a repo, but then managed to accidentally delete the branch I initiated the request from. The maintainer of the project has requested I make a couple changes.. now I’m stuck.

Github still has the PR, but now shows the source of the branch as “unknown repository”.

I was able to recover the exact commit and re-push that (it has the same commit hash as the commit in the PR), but it still shows as “unknown repository”.

Is there a way to push directly into the PR itself?