I am probably leading you astray since I do not have a ssh server installed on a windows computer. I am using another linux computer. However the "scp: ambiguous target" is due to the spaces in the destination path. You need to add backslashes to escape the spaces. In a script you need to add two backslashes but I have not tried to see if it also works in expect.
cp -r "$current_folder" username@hostname:"/dir1/main\ dir/writehere/"
Here is my test code. I am passing the source directory as a command line argument.
Code:
#!/usr/bin/expect -f
set timeout 9
set directory [lindex $argv 0]
if {[llength $argv] == 0} {
send_user "Usage: upload directory\n"
exit 1
}
spawn scp -r "$directory" user@host:/upload_directory
expect {
timeout { send_user "\nFailed to get password prompt\n"; exit 1 }
eof { send_user "\nSSH failure for server\n"; exit 1 }
"*assword"
}
send "password\r"
expect {
timeout { send_user "\nLogin failed. Password incorrect.\n"; exit 1}
"*\$ "
}
send_user "\nPassword is correct\n"