-2

I often find myself using ssh and sftp side-by-side in my Ubuntu terminal. A typical workflow looks like this:

  1. Log into some server with SSH and SFTP using the same public key on separate terminal windows.
  2. Create a directory with SSH.
  3. put some files into the directory with SFTP.
  4. Set permissions with chmod over SSH.

It can be kind of annoying doing all of this with two terminal windows, so I'd really prefer if I could make it appear that this is all happening within a single process.

The questions I have are:

Is there a good reason the ssh and sftp processes need to be kept separate? Or would it be "safe" for me to go ahead and write an application that combines them?

Thanks!

Update: It appears that sftp supports many common terminal commands. However, it still does not support any arbitrary terminal command, as is the case with ssh. So I would still like to see an answer to these questions rather than a justification as to why an answer is unnecessary.

Jake
  • 264
  • 2
  • 9
  • sftp has a chmod command. – user9517 Jul 31 '16 at 07:14
  • @iain Thanks...`chmod` was just an example though. More generally I want to have all of the capabilities of `ssh` and `sftp` combined in one process. – Jake Jul 31 '16 at 07:20
  • @Jake What you are asking is not possible. Let people provide you with alternatives and information that will let you do what you want to do in another way. – Ryan Babchishin Jul 31 '16 at 07:28
  • @RyanBabchishin It is certainly possible. All you would need to do is figure out an intuitive way to route sftp commands to an sftp client, and ssh commands to an ssh client. I am just wondering if it makes sense to write one myself or if I can save myself some work by using an existing solution. – Jake Jul 31 '16 at 07:33
  • @Jake Your initial question until you edited it was not clear enough... so relax. I'm here to help. See my answer. I found a solution for you once I realized what you wanted. – Ryan Babchishin Jul 31 '16 at 07:36
  • BTW we don't do product or service recommendations - we have a specific close reason for that. – user9517 Jul 31 '16 at 08:09
  • I don't think there is anything wrong with the question that it has to be downvoted (and that too twice). There are many highly voted questions out there on SO that can be answered by glancing at a man page. I think that the questioner faced a genuine problem here: Transferring files multiple times and running few common shell commands without having to re-authenticate every time. I think that the tendency should be to just avoid upvoting especially when there is someone else out there who is making an effort to help. – tejus Jul 31 '16 at 08:17
  • Do you have an SSH *server* running on your workstation, i.e. the system where you run your sftp and ssh clients? If yes, I eventually have an idea which could get you close to what you want. – Binarus Jul 31 '16 at 09:57
  • @Binarus Yes. I am essentially looking for a process that would multiplex between separate ssh and sftp connections. – Jake Jul 31 '16 at 11:35
  • @Jake I think you misunderstood my question, or my words were not clear enough. What I meant to ask is if the box where you work has an SSH *server* running so that connections from other machines *to* that box are possible (and not only connections *from* that box to remote machines).. – Binarus Jul 31 '16 at 13:08
  • @Binarus I didn't misunderstand. I have an SSH server running on the box I have in mind. – Jake Jul 31 '16 at 19:06
  • Not sure why this question is so downvoted, it's a useful/interesting question with a clear problem and attempted solutions. I wanted to ask a similar thing and the answers to this question effectively answered my own. Upvoted. – Tasos Papastylianou Feb 18 '22 at 12:51

3 Answers3

7

There is nothing like "SSH commands". Those are shell commands. To an SSH terminal/client, the shell is just a black box with an input and an output. The client does not even understand that you type some commands, let alone understanding them.

So any solution that does what you ask for, would have to be tailored for a certain system and shell, to be able to understand what you are doing.

A theoretical client could of course have a specific command or prefix that you would use to specify, if the command you are typing is a shell or SFTP command. Similarly to the ftp escape-to-local-shell prefix/command !.

But even then you may have difficulties matching the current working directories. If for nothing else then because the SFTP can be chrooted and the shell not. Bear in mind that the SFTP is an independent system, that in theory may use a completely different file system representation.

So the conclusion is, that this is doable, but it's so much hacking and so much system- and shell- specific that it's hardly feasible to make the system universal. A reliable solution would require some server-side components (like a special type of a shell).


I know what I'm writing about, because I have implemented bit of this for my SFTP client, the WinSCP. There, within a SFTP session, you can open a terminal/console window, which starts an shell session and changes its working directory to the current SFTP working directory (by sending the shell cd command). So I know how hackish and unreliable this is.

Martin Prikryl
  • 7,756
  • 2
  • 39
  • 73
  • I realize that SSH doesn't have "SSH commands". I also indicated that I am interested in wrapping two particular clients - Ubuntu's default `ssh` and `sftp` clients. Basically when I use the `put` command, I want my process to use `sftp`. When I use `grep "some_string"`, I want the process to use `ssh`. So this hypothetical process would just combine `ssh` and `sftp` and route whatever I type into the terminal. From all of the responses I am gathering that no such application exists, so I'll just write it myself. Thank you for your input! – Jake Jul 31 '16 at 11:43
1

Use sshfs to mount the remote filesystem. Then run commands or copy files just as you would do on your local system. Refer to your system's documentation to learn how it is used.

tejus
  • 174
  • 1
  • 1
  • 10
0

I'm not aware of anything that literally combines sftp and ssh into the single interface that you have described. Without knowing in much more detail exactly what you want to see out of such a client, I cannot give a better answer.

There are other ways of doing the things you describe.

sftp can do all of that

rbabchis@haze:~/tmp$ sftp localhost
rbabchis@localhost's password: 
Connected to localhost.
sftp> mkdir test
sftp> cd test
sftp> put /home/rbabchis/chicken.JPG
Uploading /home/rbabchis/chicken.JPG to /home/rbabchis/test/chicken.JPG
/home/rbabchis/chicken.JPG                                                                                             100% 2035KB   2.0MB/s   00:00    
sftp> chmod 777 chicken.JPG
Changing mode on /home/rbabchis/test/chicken.JPG
sftp> quit
rbabchis@haze:~/tmp$ 

Transfers while in an SSH terminal session

But if are talking about transferring files while at a remote bash prompt over SSH, I have yet to see a standard way of doing this. Though, your question did remind me of the 90s where we used things like Zmodem to transfer over a terminal session. So I googled it and look what I found.

Check this out (using Zmodem over ssh):

http://www.extraputty.com/features/zmodem.html

http://zssh.sourceforge.net/

Jake
  • 264
  • 2
  • 9
Ryan Babchishin
  • 6,260
  • 2
  • 17
  • 37
  • Thanks - I was not aware that many of these commands were supported by `sftp`. However I still want the two combined into one process so I'm looking for answers to the main questions that I posted. – Jake Jul 31 '16 at 07:24
  • By philosophy and design votes are anonymous and **neither voting [up](//$SITEURL/help/privileges/vote-up) nor voting [down](//$SITEURL/help/privileges/vote-down) requires any mandatory explanation**. The tooltip that appears when your mouse pointer hovers over the down button states: *"this answer is not not useful"*. – Jenny D Jul 31 '16 at 07:40