RFE: Change directory when opening PuTTY session
would it be possible to set the current directory in PuTTY to that one opened in WinSCP?
Lars
Advertisement
Advertisement
Advertisement
~/.winscptargetdir
.cshrc (.bashrc ...) on the target machine with:
set WINSCP_FNAME=$HOME/.winscptargetdir if ( -f $WINSCP_FNAME) then cd `cat $WINSCP_FNAME` rm -f $WINSCP_FNAME endif
.cshrc, it picks up the directory and deletes the file.
~/.*rc file depends on user shell.
echo !/ > ~/.winscptargetdir
.bashrc:
if [ -f $HOME/pwdputtyscript.sh ] then source $HOME/pwdputtyscript.sh cd $WINSCP rm -f $HOME/pwdputtyscript.sh fi
echo WINSCP=!/ > ~/pwdputtyscript.sh
Advertisement
.bashrc as mentioned above (I changed the variable name):
if [ -f $HOME/pwdputtyscript.sh ] then source $HOME/pwdputtyscript.sh cd $PUTTYSTARTDIR rm -f $HOME/pwdputtyscript.sh fi
"C:\mydir\WinSCPPutty.exe" !U !P !@ !/
Shift+Ctrl+Alt+P
Program.cs:
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; using System.Diagnostics; namespace WinSCPPutty { class Program { static void Main(string[] args) { //args = [user pass host dir] string user, pass, host, dir; if (args.Length < 3) return; if (args.Length < 4) dir = "~"; user = args[0]; pass = args[1]; host = args[2]; dir = args[3]; string puttyexe = @"C:\Program Files (x86)\PuTTY\putty.exe"; //you'll need to edit the putty location as needed string filename = Path.GetTempPath() + "cdputty.txt"; string txt = "echo PUTTYSTARTDIR=" + dir + " > ~/pwdputtyscript.sh"; string logintxt = user + "@" + host + " -pw " + pass; File.WriteAllText(filename, txt); ProcessStartInfo ps = new ProcessStartInfo(puttyexe, logintxt + " -m \"" + filename + "\""); ps.WindowStyle = ProcessWindowStyle.Hidden; Process p = Process.Start(ps); p.WaitForExit(); File.Delete(filename); Process.Start(puttyexe, logintxt); } } }
~/pwdputtyscript.sh on the remote computer. It then launches PuTTY, logs you in, and the .bashrc stuff brings you to the correct directory and cleans everything up. Importantly, no information about your username or password are ever saved in any file... they're all being transmitted between applications as arguments.
%ProgramFiles%\PuTTY\putty.exe -t -m "%TEMP%\putty.txt" !`cmd.exe /c echo cd "!/" ; $($SHELL) > "%TEMP%\putty.txt"`
putty.txt in you temporary directory.
cd "/home/user"; $($SHELL)
That page only copies WinSCP documentation:I have found this page where it is solved: <removed by admin>
Advertisement
tail -f
sudo su - so I have to account for PuTTY launching non elevated)
if [ -f $HOME/tailputtyscript.sh ] then . $HOME/tailputtyscript.sh rm -f $HOME/tailputtyscript.sh fi
echo clear > /home/!U/tailputtyscript.sh; echo >> /home/!U/tailputtyscript.sh; echo sudo tail -f "!/!" >> /home/!U/tailputtyscript.sh; chmod 777 /home/!U/tailputtyscript.sh
rm -f $HOME/tailputtyscript.sh doesn't remove the file.
Advertisement
You can post new topics in this forum