【问题标题】:bash script to upload files to sftp将文件上传到 sftp 的 bash 脚本
【发布时间】:2015-06-07 13:25:14
【问题描述】:

我希望创建一个智能脚本来将文件上传到 sftp 站点。我无法使用 scp,因为我无法控制 sftp 站点,而且供应商不允许公钥身份验证。

#!/bin/bash

            read -p "Do you want to list the sftp site contents (y/n): " list
            read -p "Upload Selected file, type the name of the file: " uploadfilename


    conenctsfttp() {
            export SSHPASS=****
            sshpass -e sftp -oBatchMode=no -b - testuser@example.com
    }

    listfiles() {
            if [[ $list = y ]];
            then
            conenctsfttp <<< $'ls\n bye'
            else
            echo not list
            fi
    }

    uploadfilen() {
    #        if [[ $uploadfilename = y ]];
    #        then
            conenctsfttp << EOF
            put $(uploadfilename)
    EOF
    }

    listfiles
    uploadfilen

如何让脚本读取文件名并将文件上传到 sftp 服务器。文件名永远不会被拾取,它会进入一个无限循环。如果可能的话,我想定义上传文件所在的位置。

【问题讨论】:

  • 那么这有什么问题呢?从 WHERE 读取文件名?
  • 当我按文件名上传时,我添加了文件名,但它进入了无限循环

标签: linux bash shell sftp


【解决方案1】:

$(uploadfilename) 应该是$uploadfilename。

$(...) 是命令替换的另一种形式。要从变量中引用(检索)值,您需要使用 $variable 语法。

【讨论】:

  • 如何调用函数uploadfilen() 不会调用它从用户输入中获取的文件名......它还需要调用连接来上传文件......
猜你喜欢
  • 2016-12-18
  • 1970-01-01
  • 1970-01-01
  • 2019-05-14
  • 2019-11-02
  • 2012-07-29
  • 2015-06-16
  • 2015-03-27
  • 1970-01-01
相关资源
最近更新 更多