问题描述
我试图使用UNIX shell脚本自动执行我的SFTP命令,但出于某种原因,它不起作用。这是我的代码如下。请分享您的想法/见解。
I am trying to automate my SFTP command using a UNIX shell script but for some reason it doesn't work. Here is my code as below. Please share your thoughts/insights.
#This ftp script will copy all the files from source directory into the local directory.
#!/bin/sh
HOST='sftp.xyz.com'
USER='ABC'
PASSWORD='123'
SRC_DIR='From_Src'
TRGT_DIR='/work/'
FILE='abc.txt'
sftp -u ${USER},${PASSWORD} sftp://${HOST} <<EOF
cd $SRC_DIR
lcd $TRGT_DIR
get $FILE
bye
EOF
echo "DONE"
当我尝试执行上面的代码时,出现以下错误。
When I try executing the above code I get the below error.
sftp: illegal option -- u
usage: sftp [-1246Cpqrv] [-B buffer_size] [-b batchfile] [-c cipher]
[-D sftp_server_path] [-F ssh_config] [-i identity_file] [-l limit]
[-o ssh_option] [-P port] [-R num_requests] [-S program]
[-s subsystem | sftp_server] host
sftp [user@]host[:file ...]
sftp [user@]host[:dir[/]]
sftp -b batchfile [user@]host
推荐答案
没有 -u
选项,请参阅了解可用选项。您可以通过以下格式传递用户名: sftp
的
There is no -u
option for sftp
, see the manual for available options. You can pass the username in this format:
sftp username@hostname
所以在你的情况下:
So in your case:
sftp sftp://${USER}@${HOST} <<EOF
这会提示您输入密码。如果您不想提示密码,请查看以下主题:
This will prompt you the password though. If you don't want a password prompt, take a look at this topic: How to run the sftp command with a password from Bash script?
这篇关于使用IBM AIX(UNIX)shell脚本自动执行sftp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!