0

所以,我在这里努力让 grunt-scp 工作。我在一家大型电信公司工作,我在他们的系统内部或在家中使用 VPN。我可以通过 ssh 进入服务器并使用 WINSCP。

所以这就是我的例子:Grunt SCP Example

现在我的代码:

先决条件:

.ftppass or secret.json. Either will work

//WIN SCP
    scp: {
        qat2: {
            options: {
                host: '123.45.678.900',
                port: 443,
                username: '<%= secret.qat2.username %>',
                password: '<%= secret.qat2.password %>'
            },
            files: [{
                    cwd: allFiles.srcPath.client,
                    src: '**/*',
                    //filter: 'isDirectory',
                    dest: allFiles.uploadServer + '**/*'
                }]
        }
    },

allFiles.srcPath.client 在我的机器文字上为:

/var/www/html/app/oauth2/v1

allFiles.uploadServer = 与上面相同,但用于服务器。

loadNpmTasks

grunt.loadNpmTasks('grunt-scp');

现在 grunt 注册任务:

//SCP
grunt.registerTask('scpThis', [
    'scp:qat2',
    'clean:qat2'
], function () {
    try {
        grunt.task.run([
            'scp:qat2',
            'clean:qat2'
        ]);
    }
    catch (e) {
        console.log("SCP Connection failed...", e);
    }
    console.log("pkg: ", pkg);
    console.log("Starting SCP SEQUENCE");
});

调用 CLEAN 清理远程服务器,我有本地的时候我

这是该部分:

 clean: {
        build: {
            src: [ //THIS IS FOR LOCAL Build
                '**/*.*',
                '/docs/*.*'
                        //,
                        //Uncomment out to use
                        //allFiles.destPath.server + '*.*'
            ]
        },
        qat2: { //Thus is for the server when it's called above
            options: {
                force: true
            },
            src: allFiles.uploadServer + '**/*'

        }
    },

结果如下:

Starting SCP SEQUENCE

//JUST SO EVERYONE KNOWS: The server IPs are FAKE and the question in the
//comments below seems like PVG50 thinks they are REAL.  Ah, they are not.
//in any case, IF THEY were real and then the REAL IPs do connect and then
//close. Thoughts on this please?

11:54:59 - Running "scp:qat2" (scp) task
11:54:59 - ssh connect 123.45.678.90
11:54:59 - ssh close 123.45.678.90
11:54:59 - 
Running "clean:qat2" (clean) task //This didn't clean the server since the connection closed...
>> 0 paths cleaned.

Done, without errors.

Execution Time (2015-12-13 19:54:57 UTC)
11:54:59 - loading tasks   1.5s  ████████████████████████████████████ 77%
scp:qat2       441ms  ███████████ 22%
Total 2s

这不起作用

这是我对 sftp 的尝试:

//SFTP - SSH EXEC
    sftp: {
        deploy: {
            command: "sudo su",
            auth: {
                host: '<%= secret.qat2.ip %>',
                port: 443,
                authKey: 'key1'
            },
            files: {
                src: allFiles.destPath.client
            },
            options: {
                path: allFiles.uploadServer,
                directoryPermissions: parseInt(777, 8),
                createDirectories: true
            }
        }
    },

//SFTP DEPLOY
    'sftp-deploy': {
        build: {//SERVERS GO HERE LIKE BELOW
            command: "sudo su",
            auth: {
                host: '<%= secret.qat2.ip %>',
                port: 443,
                authKey: 'key1'
            },
            cache: 'sftpCache.json', //OMIT from Source Control Stores Locally
            expand: true,
            src: [
                allFiles.destPath.client + 'images/{,*/}*.*',
                allFiles.destPath.client + 'images/*.jpg',
                allFiles.destPath.client + 'images/*.png',
                allFiles.destPath.client + 'scripts/config/*.json',
                allFiles.destPath.client + 'tmpl/*.js',
                allFiles.destPath.client + '*.html',
                allFiles.destPath.client + 'views/*.html',
                allFiles.destPath.client + 'views/**/*.html',
                allFiles.destPath.client + 'favicon.ico',
                allFiles.destPath.client + '.htaccess'
            ],
            dest: allFiles.uploadServer,
            concurrency: 4,
            progress: true
        }
    },

现在我运行 grunt sftpDeployThis 的结果

23:21:59 - Running "sftpDeployThis" task
23:21:59 - Starting SFTP SERVER DEPLOYMENT SEQUENCE
23:21:59 - Running "sftp-deploy:build" (sftp-deploy) task
23:21:59 - Warning: /var/www/html/app/oauth2/v1/images/{,*/}*.* is not an existing location Use --force to continue.
23:21:59 - 
Aborted due to warnings.
23:21:59 - 

Execution Time (2015-12-13 07:21:58 UTC)
23:21:59 - loading tasks      1.4s  ███████████████████████████████████████████ 99%
sftp-deploy:build  15ms  █ 1%
Total 1.4s

我已经使用 grunt 2 年了,这个让我很难过。

我想做的事:

  1. 连接到服务器
  2. 清理部署目录
  3. 将已编译的应用程序从我的机器推送到服务器
  4. 运行我拥有的脚本,无论哪个都可以
  5. 接收 DONE WITHOUT ERRORS 实际有效的通知
  6. 在服务器上使用 WINSCP 验证文件确实存在(这工作正常 - 我的意思是查看目录。)

感谢所有人提供的任何帮助

4

0 回答 0