I wrote a sftp expect script to upload and download files.
I put the script file in a folder. And double click the script to run the script to log in the remote server, but every time my script will log in the server in home folder not in the folder that where the script is.
#!/usr/bin/env expect
set login "username"
set addr "server.com"
set pw "mypassword"
set timeout -1
sleep 1
spawn sftp $login@$addr
expect "Password:" {send "$pw\r"}
sleep 1
interact
For example, I put this script on /Desktop and if I want to upload some files to my server from /Desktop in my local machine, I still have to cd into /Desktop and than run this script, if I just double click to execute the script it will log into my server from the ~ or /root whatever the default directory is. I want to log in my server from the directory where the script is.
You might want
cd [file dirname $argv0]
to change into the directory where the script lives.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments