Giter Club home page Giter Club logo

Comments (5)

AdsonCicilioti avatar AdsonCicilioti commented on July 20, 2024 1

NicE!
Sounds good!

I have not had time to test yet. But I must do so soon. I come back with my observations. But I trust it will work well!

Thanks @mkloubert !

from vscode-deploy-reloaded.

mkloubert avatar mkloubert commented on July 20, 2024

@AdsonCicilioti

I released a new version 0.65.0, which is now able to define logic for "upload events" in SFTP and FTP targets.

For that, you can define scripts, which can use the underlying raw connection to do anything you want.

In your case (if you use SFTP):

First setup your target:

{
    "deploy.reloaded": {
        "targets": [
            {
                "type": "sftp",
                "name": "My SFTP folder",

                "uploaded": "./uploadedToSFTP.js",
                "uploadedOptions": 23979
            }
        ]
    }
}

Create a file, called uploadedToSFTP.js, inside your .vscode folder or .vscode-deploy-reloaded subfolder inside your home directory:

// s. https://nodejs.org/api/path.html
const Path = require('path');
// s. https://code.visualstudio.com/docs/extensionAPI/vscode-api
const vscode = require('vscode');

// script entry
// for 'args', s. https://mkloubert.github.io/vscode-deploy-reloaded/interfaces/_plugins_sftp_.sftpuploadedmoduleexecutorarguments.html
exports.execute = async function(args) {
    if (args.context.error) {
        return;  // rethrow error
    }

    // s. https://github.com/jyu213/ssh2-sftp-client
    const CONN = args.context.connection;

    const DIR = Path.dirname( args.context.file );
    if ('/' !== DIR) {  // only if not root
        await setMode(CONN, DIR, '755');  // mode for directory
    }    

    await setMode(CONN, args.context.file, '644');  // mode for file
};

// execute 'chmod' for a file
function setMode(conn, path, mode) {
    mode = parseInt(mode, 8);

    return new Promise((resolve, reject) => {
        try {
            conn.sftp.chmod(path, mode, (err) => {
                if (err) {
                    reject(err);
                }
                else {
                    resolve();
                }
            });
        } catch (e) {
            reject(e);
        }
    });
}

For FTP targets, this is quite similar.

You only need to replace the part

            conn.sftp.chmod(path, mode, (err) => {
            });

with code of the API, that is provided by ftp or jsftp modules.

This depends on what you have defined in the engine setting of the underlying target.

from vscode-deploy-reloaded.

mkloubert avatar mkloubert commented on July 20, 2024

@AdsonCicilioti

Btw.: If you want to execute a command on a SFTP server, you can try this:

function executeCommand(conn, commandToExecute) {
    return new Promise((resolve, reject) => {
        try {
            conn.client.exec(commandToExecute, (err, stream) => {
                if (err) {
                    reject( err );
                    return;
                }

                let output = Buffer.alloc(0);

                stream.once('error', (streamErr) => {
                    reject( streamErr );
                });

                stream.once('end', () => {
                    resolve( output );
                });

                stream.on('data', (chunk) => {
                    if (chunk) {
                        output = Buffer.concat([ output, chunk ]);
                    }
                });
            });
        } catch (e) {
            reject(e);
        }
    });
}

from vscode-deploy-reloaded.

mkloubert avatar mkloubert commented on July 20, 2024

@AdsonCicilioti

I have reimplemented command feature from vs-deploy in version 0.66.1 for SFTP and FTP targets.

from vscode-deploy-reloaded.

AdsonCicilioti avatar AdsonCicilioti commented on July 20, 2024

Hey @mkloubert !

Any exemples or Wiki doscs for this exemple?

from vscode-deploy-reloaded.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.