<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Sebastião Lutonda on Medium]]></title>
        <description><![CDATA[Stories by Sebastião Lutonda on Medium]]></description>
        <link>https://medium.com/@lutonda?source=rss-6480279a36ea------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*ySojPOrKAaBoExXN</url>
            <title>Stories by Sebastião Lutonda on Medium</title>
            <link>https://medium.com/@lutonda?source=rss-6480279a36ea------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 19:26:05 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@lutonda/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Create a simple Cloud Storage API using the Limonade framework]]></title>
            <link>https://medium.com/@lutonda/create-a-simple-cloud-storage-api-using-the-limonade-framework-01492f089660?source=rss-6480279a36ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/01492f089660</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[cloud-storage]]></category>
            <category><![CDATA[ftp]]></category>
            <dc:creator><![CDATA[Sebastião Lutonda]]></dc:creator>
            <pubDate>Sat, 25 Nov 2023 05:09:52 GMT</pubDate>
            <atom:updated>2023-11-25T05:09:52.369Z</atom:updated>
            <content:encoded><![CDATA[<p>Below is an extended version of the PHP FTP Explorer API using the Limonade framework, including functionalities to list folders, upload files, download files, and create files on an FTP server.</p><h3>Features:</h3><p>— List content of folders in the cloud storage via FTP.</p><p>— Upload files to the cloud storage.</p><p>— Download files from the cloud storage.</p><p>— Create new files in the cloud storage.</p><p>— Create folders/directories in the cloud storage.</p><h3>Prerequisites:</h3><ul><li>PHP installed on your machine</li><li>Composer package management installed</li><li>Basic understanding of PHP</li><li>Familiarity with FTP operations</li></ul><h3>Steps:</h3><h4>1. Create the project structure:</h4><blockquote>$ mkdir my_storage_project &amp;&amp; cd my_storage_project # create api folder</blockquote><blockquote>$ echo “{ “require”: { “sofadesign/limonade”: “<a href="http://twitter.com/dev">@dev</a>” } }” &gt;&gt; composer.json # initialize composer json</blockquote><blockquote>$ composer require sofadesign/limonade # intall limonade through composer</blockquote><blockquote>$ touch index.php # Create inital api file</blockquote><h4>2. Update index.php:</h4><pre>&lt;?php<br>require_once &#39;vendor/autoload.php&#39;; // Load Limonade autoloader<br><br>// Define FTP configuration<br>$ftpConfig = [<br>    &#39;host&#39; =&gt; &#39;ftp.example.com&#39;,<br>    &#39;username&#39; =&gt; &#39;your_ftp_username&#39;,<br>    &#39;password&#39; =&gt; &#39;your_ftp_password&#39;<br>];<br><br>// Function to establish FTP connection<br>function connectFTP() {<br>    global $ftpConfig;<br>    $ftpConnection = ftp_connect($ftpConfig[&#39;host&#39;]);<br>    $login = ftp_login($ftpConnection, $ftpConfig[&#39;username&#39;], $ftpConfig[&#39;password&#39;]);<br>    <br>    if (!$ftpConnection || !$login) {<br>        halt(&quot;Failed to connect or login to FTP server&quot;);<br>    }<br>    <br>    return $ftpConnection;<br>}<br><br>// Define route to list FTP folder contents<br>dispatch(&#39;/ftp-list/:folder&#39;, function () {<br>    $folder = params(&#39;folder&#39;);<br>    $ftpConnection = connectFTP();<br>    <br>    $files = ftp_nlist($ftpConnection, $folder);<br>    <br>    ftp_close($ftpConnection);<br>    <br>    return $files;<br>});<br><br>// Define route to upload file to FTP server<br>post(&#39;/upload&#39;, function () {<br>    $uploadedFile = $_FILES[&#39;file&#39;];<br>    $ftpConnection = connectFTP();<br>    <br>    if (ftp_put($ftpConnection, $uploadedFile[&#39;name&#39;], $uploadedFile[&#39;tmp_name&#39;], FTP_BINARY)) {<br>        return &quot;File uploaded successfully&quot;;<br>    } else {<br>        return &quot;Error uploading file&quot;;<br>    }<br>    <br>    ftp_close($ftpConnection);<br>});<br><br>// Define route to download file from FTP server<br>dispatch(&#39;/download/:file&#39;, function () {<br>    $file = params(&#39;file&#39;);<br>    $ftpConnection = connectFTP();<br>    <br>    $fileContent = ftp_get($ftpConnection, &#39;php://output&#39;, $file, FTP_BINARY);<br>    <br>    ftp_close($ftpConnection);<br>    <br>    if ($fileContent) {<br>        header(&#39;Content-Type: application/octet-stream&#39;);<br>        header(&#39;Content-Disposition: attachment; filename=&quot;&#39; . $file . &#39;&quot;&#39;);<br>        echo $fileContent;<br>        exit();<br>    } else {<br>        halt(&quot;Error downloading file&quot;);<br>    }<br>});<br><br>// Define route to create a file on FTP server<br>post(&#39;/create-file&#39;, function () {<br>    $fileName = $_POST[&#39;file_name&#39;];<br>    $fileContent = $_POST[&#39;file_content&#39;];<br>    $ftpConnection = connectFTP();<br>    <br>    $tempHandle = tmpfile();<br>    fwrite($tempHandle, $fileContent);<br>    fseek($tempHandle, 0);<br>    <br>    if (ftp_fput($ftpConnection, $fileName, $tempHandle, FTP_BINARY)) {<br>        fclose($tempHandle);<br>        return &quot;File created successfully&quot;;<br>    } else {<br>        fclose($tempHandle);<br>        return &quot;Error creating file&quot;;<br>    }<br>    <br>    ftp_close($ftpConnection);<br>});<br><br>// Run the application<br>run();</pre><p>Replace &#39;ftp.example.com&#39;, &#39;your_ftp_username&#39;, and &#39;your_ftp_password&#39; in the FTP configuration with your actual FTP server details.</p><h4>3. Run the project:</h4><pre>$ php -S localhost:8000</pre><p>To test the API, use tools like Postman or cURL:</p><ul><li>GET request to list FTP folder contents:</li></ul><pre>GET http://localhost:8000/ftp-list/folder_name</pre><ul><li>POST request to upload a file:</li></ul><pre>POST http://localhost:8000/upload Form-data: key = &quot;file&quot;, value = &lt;select file to upload&gt;</pre><ul><li>GET request to download a file:</li></ul><pre>GET http://localhost:8000/download/file_name</pre><ul><li>POST request to create a file:</li></ul><pre>POST http://localhost:8000/create-file Form-data:  - key = &quot;file_name&quot;, value = &quot;new_file.txt&quot; - key = &quot;file_content&quot;, value = &quot;Content of the new file&quot;</pre><h3>Important Notes:</h3><ul><li>Ensure you handle errors, perform proper input validation, and implement security measures when developing a production-ready FTP Explorer API.</li><li>Limonade is a lightweight framework suitable for simple applications. For larger or more complex projects, consider using more robust frameworks.</li><li>Test thoroughly and ensure proper access permissions and error handling for all FTP operations.</li></ul><h3>Conclusion:</h3><p>This should help you create a PHP FTP Explorer API with functionalities for listing folders, uploading, downloading, and creating files using the Limonade framework. Adjust the code according to your specific requirements and use cases.</p><p>Github repo</p><p><a href="https://github.com/Hiperbite/cloud_storage_gateway">https://github.com/Hiperbite/cloud_storage_gateway</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=01492f089660" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Construindo um Mini Load Balancer em Node.js]]></title>
            <link>https://medium.com/@lutonda/construindo-um-mini-load-balancer-em-node-js-7ff06d769a31?source=rss-6480279a36ea------2</link>
            <guid isPermaLink="false">https://medium.com/p/7ff06d769a31</guid>
            <category><![CDATA[serverless-architecture]]></category>
            <category><![CDATA[proxy-server]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[load-balancing]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Sebastião Lutonda]]></dc:creator>
            <pubDate>Mon, 21 Aug 2023 15:41:05 GMT</pubDate>
            <atom:updated>2023-08-21T15:41:05.605Z</atom:updated>
            <content:encoded><![CDATA[<p>Introdução:</p><p>Um Load Balancer é uma ferramenta essencial para garantir alta disponibilidade e escalabilidade em sistemas de computação. Ele distribui as requisições de entrada entre diversos servidores para otimizar o desempenho e minimizar o tempo de resposta. Neste artigo, vamos explorar como construir um Mini Load Balancer simples usando Node.js, uma plataforma popular para construção de aplicativos web escaláveis.</p><p>Passo 1: Configurando o Ambiente</p><p>Antes de começarmos, certifique-se de ter o Node.js instalado em seu sistema. Você pode fazer o download da versão mais recente em <a href="https://nodejs.org/">https://nodejs.org</a>. Depois de instalado, crie uma pasta para o projeto e inicie um novo projeto Node.js executando.</p><pre>$ npm init</pre><p>Passo 2: Criando o Load Balancer</p><ol><li>Instalação de Dependências:</li></ol><p>Para este projeto, vamos utilizar duas bibliotecas principais: http, que é um módulo nativo do Node.js para criar um servidor web, e http-proxy, uma biblioteca que nos permitirá redirecionar as requisições entre servidores.</p><p>Execute o seguinte comando no terminal para instalar as dependências:</p><pre>$ npm install http http-proxy</pre><p>2. Crie um arquivo chamado loadBalancer.js e adicione o seguinte código:</p><pre>const http = require(&#39;http&#39;);<br>const httpProxy = require(&#39;http-proxy&#39;);<br>// Lista de servidores disponíveis <br>const servers =<br>    [<br>        { host: &#39;localhost&#39;, port: 3001 },<br>        { host: &#39;localhost&#39;, port: 3002 },<br>        // Adicione mais servidores conforme necessário <br>    ];<br>const methods = &#39;sequential&#39;;<br>// Criando o proxy <br>const proxy = httpProxy.createProxyServer();<br>// Criando o servidor Load Balancer <br><br>const server = http.createServer((req, res) =&gt; {<br>    let index = {<br>        sequential: () =&gt; index === servers.length - 1 ? 0 : index + 1,<br>        random: () =&gt; Math.floor(Math.random() * servers.length),<br>    }[`${methods}`];<br><br>    const selectedServer = servers[index];<br>    console.log(<br>        `http://${selectedServer.host}:${selectedServer.port}`,<br>    )<br>    // Redireciona a requisição para o servidor selecionado   <br>    proxy.web(req, res,<br>        {<br>            target: `http://${selectedServer.host}:${selectedServer.port}`<br>        });<br>});<br><br>// Inicia o servidor Load Balancer na porta 8080 <br>server.listen(8080, () =&gt;<br>    console.log(&#39;Load Balancer rodando na porta 8080&#39;)<br>);</pre><p>Passo 3: Executando o Load Balancer</p><p>Para executar o Load Balancer, basta abrir um terminal na pasta do projeto e digitar:</p><pre>$ node loadBalancer.js</pre><p>Se tudo estiver configurado corretamente, o Load Balancer estará ativo e pronto para redirecionar as requisições para os servidores especificados.</p><p>Conclusão:</p><p>Neste artigo, exploramos como construir um Mini Load Balancer em Node.js. Embora esse exemplo seja bastante simples, ele ilustra os princípios básicos do balanceamento de carga e como distribuir eficientemente as requisições entre diversos servidores. Ao personalizar e expandir esse projeto, você pode criar um Load Balancer mais robusto e adaptado às necessidades específicas de seus aplicativos.</p><p>Lembre-se de que este é apenas um ponto de partida, e existem muitas outras considerações a serem feitas para implementações mais complexas em ambientes de produção. Sempre leve em conta as melhores práticas de segurança e escalabilidade ao desenvolver sistemas distribuídos.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7ff06d769a31" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>