Reputation: 35
I'm relatively new to using sftp in scripting format (bash shell on Mac OSX High Sierra). I am having issues changing dirs once logged into the remote server. I want to cd to 'FTP PDF (Download) to CR' Here is my script(edited):
#!/bin/bash
expect -c "
spawn sftp [email protected]
expect \"Password\"
send \"xxxxxxx\r\"
expect \"sftp>\"
send \"cd CR\ Reports\r\"
#DIR TO CD to "CR REPORTS"
expect \"sftp>\"
send \"bye\r\"
expect \"#\"
"
Upvotes: 1
Views: 711
Reputation: 247062
This is really just an formatted comment expanding on @meuh's comment.
You're having quoting trouble. You could use single quotes or a quoted heredoc to make your life easier
#!/bin/bash
expect <<'END_EXPECT'
spawn sftp [email protected]
expect "Password"
send "xxxxxxx\r"
expect "sftp>"
send "cd 'CR Reports'\r"
#DIR TO CD to "CR REPORTS"
expect "sftp>"
send "bye\r"
expect "#"
END_EXPECT
Or, just an expect script:
#!/usr/bin/expect -f
spawn sftp [email protected]
expect "Password"
send "xxxxxxx\r"
expect "sftp>"
send "cd 'CR Reports'\r"
#DIR TO CD to "CR REPORTS"
expect "sftp>"
send "bye\r"
expect "#"
Upvotes: 1