Sooraj S Padmanabhan
2014-08-18 08:27:26 UTC
Hi,
Given below is the command that I use to connect to my SFTP server. When I issue the command, it just asks for the password.
sftp -oProxycommand="nc -x<:SquidServer_IP>:3128 -Xconnect <SFTPServer_IP> 2222" ***@localhost
I want to use expect script to auto login to SFTP server and print its contents. Given below is the script that I wrote.
#!/usr/bin/expect -f
set prompt sftp>
set timeout 25
set passwd "test"
if [catch {spawn sftp -oProxycommand="nc -x<:SquidServer_IP>:3128 -Xconnect <SFTPServer_IP> 2222" ***@localhost} error] {
send_user "$error"
send_user "spawn error"
} else {
expect "password:"
send "$passwd\r"
expect "$prompt"
send "$ls -lrt\r"
}
But it errors out with the following error.
spawn sftp -oProxycommand="nc -x<:SquidServer_IP>:3128 -Xconnect <SFTPServer_IP> 2222" ***@localhost
sftp: illegal option -- x
usage: sftp [-1Cv] [-B buffer_size] [-b batchfile] [-F ssh_config]
[-o ssh_option] [-P sftp_server_path] [-R num_requests]
[-S program] [-s subsystem | sftp_server] host
sftp [user@]host[:file ...]
sftp [user@]host[:dir[/]]
sftp -b batchfile [user@]host
When I'm doing it manually, it works fine. Could someone please help me out here?
Regards,
Sooraj
Given below is the command that I use to connect to my SFTP server. When I issue the command, it just asks for the password.
sftp -oProxycommand="nc -x<:SquidServer_IP>:3128 -Xconnect <SFTPServer_IP> 2222" ***@localhost
I want to use expect script to auto login to SFTP server and print its contents. Given below is the script that I wrote.
#!/usr/bin/expect -f
set prompt sftp>
set timeout 25
set passwd "test"
if [catch {spawn sftp -oProxycommand="nc -x<:SquidServer_IP>:3128 -Xconnect <SFTPServer_IP> 2222" ***@localhost} error] {
send_user "$error"
send_user "spawn error"
} else {
expect "password:"
send "$passwd\r"
expect "$prompt"
send "$ls -lrt\r"
}
But it errors out with the following error.
spawn sftp -oProxycommand="nc -x<:SquidServer_IP>:3128 -Xconnect <SFTPServer_IP> 2222" ***@localhost
sftp: illegal option -- x
usage: sftp [-1Cv] [-B buffer_size] [-b batchfile] [-F ssh_config]
[-o ssh_option] [-P sftp_server_path] [-R num_requests]
[-S program] [-s subsystem | sftp_server] host
sftp [user@]host[:file ...]
sftp [user@]host[:dir[/]]
sftp -b batchfile [user@]host
When I'm doing it manually, it works fine. Could someone please help me out here?
Regards,
Sooraj