Open Xftp from Xshell with current directory [6]

Open Xftp from Xshell with current directory

Friday, March 29, 2013 1:36 PM - ob_ivan

As it is stated here:Xshell Knowledgebase : When I open Xftp from Xshell, I get the quot;Cannot display the remote folderquot; message -- Xftp wouldn't start in the same directory as Xshell session is open with if it occurs to be the user's home directory or its subdirectory because "Xshell cannot translate '~' into the real directory path".

If I run pwd, I get the full (absolute) path. If I access $PWD, it holds the same. Why Xshell cannot use these to pass them to Xftp?

I use Xshell+Xftp a lot to work on a hosting where everything is located inside my home directory. So each time I start an Xftp session, I have to navigate down all the subfolders to get where I already am in Xshell.

Program Ver. : Xshell 4


Re: Open Xftp from Xshell with current directory

Sunday, March 31, 2013 7:38 PM - Support

Xshell gets the current working directory from the title message. There are few things you need to setup in the remote host to use this feature.

1. Set the terminal type to xterm
2. Xshell takes what is after the colon (:) characters from the title and uses it as the path of the current working directory. Try adding the following lines in the .bashrc file to add path at the end of the title.

PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"'

If the problem persists, please send us the followings:

1. In Xftp, right click on the remote folder pane and select View > Session Log. Include everything in the log view.
2. Do 'echo $TERM' and send us the result.
3. After connecting to the server, traverse to the folder and see if the current folder path is displayed in the Xshell title bar correctly. If not, take a screenshot of entire Xshell window and include it in your next posting.




---
Technical Support


Re: Open Xftp from Xshell with current directory

Tuesday, April 2, 2013 12:19 PM - ob_ivan

It works! Thank you so much!

The prompt command I actually use in .bashrc is:

export PS1='\[\033[01;32m\]\t\

\[\033[01;32m\]\u@\h\[\033[01;36m\]:\w \$\[\033[00m\] '

(it prints current time and does some coloring)

\w is equivalent for "$PWD with $HOME substituted with a tilde".

So the trick was to place a colon before \w. Hope this makes its way to the Knowledge Base and helps a lot of people!


Re: Open Xftp from Xshell with current directory

Tuesday, April 2, 2013 11:26 PM - ob_ivan

Hm, now there is a strange behaviour. If I set my prompt as above, it works at first, but once I close both xshell and xftp (not just disconnect, but also actually close the applications) and run again, the problem is here again.

What do I do:
1. Run Xshell and connect to server.
2. Click "New File Transfer" to run Xftp.
3. Open .bashrc and write:

PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"'

(the one you suggested)
4. Disconnect in Xftp and close it.
5. Disconnect in Xshell and close it.
6. Run Xshell again and connect to server.
7. cd to a subdirectory inside my home directory.
8. Click "New File Transfer" to run Xftp.
Assert A: Xftp starts in the subdirectory.
9. Open .bashrc and substitute

PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"'

with

export PS1='\[\033[01;32m\]\t\

\[\033[01;32m\]\u@\h\[\033[01;36m\]:\w \$\[\033[00m\] '

(the one I used)
10. Disconnect in Xftp and close it.
11. Disconnect in Xshell but leave it open.
12. Connect to server in Xshell.
13. cd to a subdirectory inside my home directory.
14. Click "New File Transfer" to run Xftp.
Assert B: Xftp starts in the subdirectory.
15. Don't make any more changes in .bashrc, disconnect in Xftp and close it.
16. Disconnect in Xshell and close it.
17. Run Xshell again and connect to server.
18. cd to a subdirectory inside my home directory.
19. Click "New File Transfer" to run Xftp.
Expected C: Xftp starts in the subdirectory.
Actual C: Xftp starts in my home directory.

The result is the same if instead of \w in my prompt I use ${PWD/#$HOME/~} as you suggested.

This brings up two questions:
1) What is wrong with my prompt?
2) Why the behaviour differs depending on whether Xshell was restarted or not?

Thanks for concern.


Re: Open Xftp from Xshell with current directory

Wednesday, April 3, 2013 11:14 PM - Support

1) What is wrong with my prompt?
It's not the prompt that Xshell uses. It is the terminal title. To see the terminal title change, do this:

a. Save the following lines in .bashrc

PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/#$HOME/~}"; echo -ne "\007"'
export PS1='\[\033[01;32m\]\t\

\[\033[01;32m\]\u@\h\[\033[01;36m\]:\w \$\[\033[00m\] '

b. Right click on Xshell tab and select the Show terminal title menu.
c. Log out of the user account and log back in.
d. Traverse to a different folders and see the Xshell title bar changing.

2) Why the behaviour differs depending on whether Xshell was restarted or not?
I am not sure why this happened. .bashrc is loaded when user logs in. Xshell remembers the last used path and coincidently you traversed to that folder before opening Xftp. And, once Xshell restarts the path is gone so the problem reappears.

Keep in mind it is terminal title that needs to have the path information not prompt.



---
Technical Support


Re: Open Xftp from Xshell with current directory

Sunday, April 7, 2013 11:14 AM - ob_ivan

Now I see, thank you!

I never noticed what you call "title message" because the "show terminal title" option was off.

Seems that the title is being set by the PROMPT_COMMAND variable, which makes sense why it wouldn't work with only PS1 set to show my fancy colored prompt.

I hope this solution gets its way to the docs.

Thank you again!


Re: Open Xftp from Xshell with current directory

Sunday, April 7, 2013 5:33 PM - Support

Thank you for the update. I am sure other users will find this article helpful. Please feel free to let us know if you have any questions.


---
Technical Support


Previous views: 264