简体   繁体   English

bash脚本将文件上传到sftp

[英]bash script to upload files to sftp

I'm looking to create a smart script to upload files to an sftp site. 我正在寻找创建一个智能脚本以将文件上传到sftp站点。 I cannot use scp because i have no control of the sftp site plus the vendor doesn't allow public key authentication. 我无法使用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

how can i make the script read the filename and upload the file to the sftp server. 我如何使脚本读取文件名并将文件上传到sftp服务器。 The file-name is never picked up and it goes into an infinite loop. 文件名永远不会被拾取,并且会进入无限循环。 If possible i like to define a location of where files are located for the upload. 如果可能的话,我想定义一个文件上传位置。

$(uploadfilename) should be $uploadfilename . $(uploadfilename)应该是$uploadfilename

$(...) is an alternative form of command substitution. $(...)是命令替换的另一种形式。 To reference (retrieve) a value from a variable, you want to use the $variable syntax. 要引用(检索)变量中的值,您想使用$variable语法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM