unix - How to CD inside a SFTP connection where the connection is established using - Shell script -


in script - create sftp connection.

i read directory value user earlier , once sftp connection established, try cd dir got user.

but not working, bec prompt goes inside server sftp connection established.

in case how make work ?

if script does, state somewhere in page,

sftp $user@$host cd $directory 

and tries else, like:

sftp $user@$host foo 

that command foo not executed in same directory $directory since you're executing new command, create new connection sftp server.

what can use "batchfile" option of sftp, i.e. construct file contains commands you'd sftp on 1 connection, example:

$ cat commands.txt cd foo/bar put foo.tgz lcd /tmp/ foo.tgz 

then, able tell sftp execute commands in 1 connection, executing:

sftp -b commands.txt $user@$host 

so, propose solution be:

  • with user's input, create temporary text file contains commands executed on 1 sftp connection, then
  • execute sftp using temporary text file "batch file"

your script like:

echo "directory in go:" read directory temp=$( mktemp /tmp/fooxxx ) echo "" > $temp echo "cd $directory" >> $temp # other commands sftp -b $temp $user@$host rm $temp 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -