I'm an Ubuntu bash newbie. I successfully login to an sFTP server using sshpass
. But once the connection is established I also need to download a directory from the server. My script cannot seem to pass the connection line though. This is what I have in my script (.sh) file:
#!/bin/bash
sshpass -p 'MY_PASSWORD' sftp -o StrictHostKeyChecking=no -o HostKeyAlgorithms=+ssh-dss MYUSER@MYSFTPSERVERADDRESS
echo "hello"
get -r Export
In the snipped above, my echo
and my get
are not executed. The terminal is waiting for my input with a sftp>
prompt.
答案 0 :(得分:1)
scp
代替sftp
和共享密钥而不是将密码放在脚本中(如果可以的话),但是如果必须使用sftp
,则会更好原因是,它可以从heredoc开始执行命令:
sshpass -p 'MY_PASS' sftp -o StrictHostKeyChecking=no -o HostKeyAlgorithms=+ssh-dss MYUSER@MYSFTPSERVERADDRESS <<EOF
get -r Export
EOF
请注意echo
不是有效的sftp
命令。
您可以在sftp
之前执行您想要执行的任何命令EOF
,并依次执行这些命令。
如果您只想获得该目录,如果可以的话,使用scp
可能更简单:
sshpass -p 'MY_PASSWORD' scp -o StrictHostKeyChecking=no -o HostKeyAlgorithms=+ssh-dss -r MYUSER@MYSFTPSERVERADDRESS:Export .