Skip to content

target_ftp

Marcel Kloubert edited this page Jul 3, 2018 · 22 revisions

Home >> Targets >> ftp

FTP(s)

Deploys to a FTP server.

Table of contents

  1. Settings
  2. Known issues
  3. Commands
  4. Event scripts
  5. Examples

Settings []

{
    "deploy.reloaded": {
        "targets": [
            {
                "type": "ftp",
                "name": "My FTP folder",
                "description": "A FTP folder",

                "dir": "/my_package_files",
                "host": "ftp.example.com", "port": 21,
                "user": "mkloubert", "password": "P@assword123!"
            }
        ]
    }
}
Name Description Supported engine(s)
alwaysAskForPassword Always ask for password and do not cache, if no password is defined. Default: (false)
alwaysAskForUser Always ask for uasername and do not cache, if no user is defined. Default: (false)
askForPassword Ask for password. Default: (false)
askForUser Ask for username. Default: (false)
beforeUpload* The path to an (event) script, which is executed BEFORE a file is going to be uploaded. Relative paths will be mapped to the .vscode subfolder of the workspace or the .vscode-deploy-reloaded folder inside the user's home directory.
beforeUploadOptions Options for the script defined in beforeUpload.
commands One or more FTP commands, which should be executed on the server. (all)
engine* Engine to use. Possible values are ftp, ftp-legacy or jsftp. Default: jsftp (all)
host* The host address of the server. Default: 127.0.0.1 (all)
password Password (all)
port* The TCP port of the server. Default: 21 or 990, if use secure FTPS (all)
rejectUnauthorized Request unauthorized server certificates or not. Default: (false) ftp, ftp-legacy
secure Set to (true) for both control and data connection encryption, control for control connection encryption only, or implicit for implicitly encrypted control connection. Default: (false) ftp, ftp-legacy
supportsDeepDirectoryCreation Server supports deep directory creation or not. Default: (false) (all)
uploaded* The path to an (event) script, which is executed AFTER a file has been uploaded or tried to be uploaded. Relative paths will be mapped to the .vscode subfolder of the workspace or the .vscode-deploy-reloaded folder inside the user's home directory.
uploadedOptions Options for the script defined in uploaded.
user Username. Default: anonymous (all)

* supports placeholders

Known issues []

Commands []

This example shows how to execute FTP commands:

{
    "deploy.reloaded": {
        "targets": [
            {
                "type": "ftp",

                "commands": {
                    "connected": [ "CWD ${remote_dir}" ],

                    "beforeUpload": [ "DELE ${remote_file}" ]
                }
            }
        ]
    }
}
Name Description
beforeDelete Commands to invoke BEFORE a file is going to be deleted.
beforeDownload Commands to invoke BEFORE a file is going to be downloaded.
beforeUpload Commands to invoke BEFORE a file is going to be uploaed.
connected Commands to invoke AFTER a connection has been established.
deleted Commands to invoke AFTER a file has been deleted.
downloaded Commands to invoke AFTER a file has been downloaded.
encoding The (output) encoding of the commands.
uploaded Commands to invoke AFTER a file has been uploaded.

Instead of using string values for commands, you can define setting objects, which provide more feature:

Name Description
command* The command to execute.
executeBeforeWriteOutputTo The (JavaScript) code to execute before output is written via 'writeOutputTo' setting. The result of the execution will be used as value to write.
writeOutputTo The name of the placeholder where to write the output to. The placeholder will be available for all upcoming executions.

* supports placeholders

Values

The following, additional placeholders are also supported:

Name Description Supported engine(s)
remote_dir The directory of the remote file.
remote_file The full path of the remote file.
remote_name The (base) name of the remote file.

Event scripts []

beforeUpload

{
    "deploy.reloaded": {
        "targets": [
            {
                "type": "ftp",
                "name": "My FTP folder",

                "beforeUpload": "./beforeUploadToFTP.js",
                "beforeUploadOptions": 5979
            }
        ]
    }
}

The beforeUploadToFTP.js file should look like that:

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

exports.execute = async function(args) {
    // args.options === 5979 (s. 'beforeUploadOptions' above)

    // raw FTP connection is stored in
    // args.context.connection (s. https://github.com/mscdex/node-ftp
    //                             or https://github.com/sergi/jsftp)

    vscode.window.showInformationMessage('File ' + args.context.file + ' is going to be uploaded...');

    // return (false) if the
    // file should NOT be uploaded
};

args implements the FTPBeforeUploadModuleExecutorArguments interface.

uploaded

{
    "deploy.reloaded": {
        "targets": [
            {
                "type": "ftp",
                "name": "My FTP folder",

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

The uploadedToFTP.js file should look like that:

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

exports.execute = async function(args) {
    // args.options === 23979 (s. 'uploadedOptions' above)

    // raw FTP connection is stored in
    // args.context.connection (s. https://github.com/mscdex/node-ftp
    //                             or https://github.com/sergi/jsftp)

    if (args.context.error) {
        vscode.window.showErrorMessage('File ' + args.context.file + ' could not be uploaded: ' + args.context.error);

        return true;  // indicates that error has been
                      // handled by script and should NOT
                      // be rethrown; otherwise return nothing
    }

    vscode.window.showInformationMessage('File ' + args.context.file + ' has been uploaded.');
};

args implements the FTPUploadedModuleExecutorArguments interface.

Examples []

Azure []

For an Azure website like http://nameofyoursite.azurewebsites.net:

{
    "deploy.reloaded": {
        "targets": [
            {
                "type": "ftp", "name": "FTP",
                "host": "waws-prod-sn1-053.ftp.azurewebsites.windows.net",
                "user": "nameofyoursite\\$nameofyoursite",
                "password": "sOmeCrYPTicL00kIngStr1nG",
                "dir": "/site/wwwroot"
            }
        ]
    }
}

You can find more information in this article.

You can’t perform that action at this time.