在bash脚本中运行SFTP命令

时间:2016-11-17 18:36:15

标签: linux unix sftp

Hi社区居民,

我有这样的要求 -

  1. 需要将csv文件从本地Linux服务器放置到远程linux / windows框。
  2. 行动 -

    1. 我们已经在本地和远程盒子之间建立了无密码连接。
    2. 能够使用以下命令sftp远程服务器 -

      put /dir/local/*.csv user@remote:/usr/dir/
      
    3. 能够使用put命令复制 -

      sftp -b Test.sh -o Port=11001 user@xxx.xx.xx.xx
    4. 尝试在bash脚本中执行上述命令,只能到sftp登录。

    5. 尝试在语句中运行批处理文件(在try 1中),如步骤1,可以看到上传数据,但是当你执行pwd时,文件夹是空的,不知道这些文件的写入位置,与try 2语句相同 - < / LI>

      尝试1 - sftp -o Port=11001 {user}@{host}:{remote_dir} <<< $'put {local_file_path}'

      尝试2 - var express = require('express'); var app = express(); var c_MyApi = require('./controller/call_MyApi'); var mongo = require('./controller/crud_mongo'); var c_email = require('./controller/api_email_verify'); var c_sql = require('./controller/consulta_sql'); var MyLink = '', id = 0; for( var i = 0 ; i < 10 ; i++){ c_sql.busca().then(function(res) { MyLink = res[0].MyLink; id = res[0].id; c_sql.marca(id).then( c_MyApi.busca(MyLink, function(a) { if (a == 0) { c_sql.atualiza(id, 'sem_email', 's/e'); } if (a == 1) { c_sql.atualiza(id, 'link_errado', 'l/e'); } else { for (var i = 0; i < a.length; i++) { var email = a[i].address; c_email.busca(email, function(e_valid) { c_sql.atualiza(id, email, e_valid) }) } } }) ) }) } } //consulta_sql.js var sql = require("seriate"); var search = function() { var exec = 'select top 1 MyLink, id from sys_robo_fila where done is null'; sql.setDefaultConfig(config); return sql.execute({ query: exec }); } var usado = function(id) { var exec = "update sys_robo_fila set done = 'r' where id = " + id + ""; sql.setDefaultConfig(config); return sql.execute({ query: exec }); } var update = function(id, email, valid) { var exec = "update sys_robo_fila set email = '" + email + "' , validacao = '" + valid + "' , done = 'ok' where id = " + id + ""; sql.setDefaultConfig(config); return sql.execute({ query: exec }); } module.exports = { busca: search, atualiza: update, marca: usado }

0 个答案:

没有答案