3

I've read the TRAMP manual and dozens of forums across the web but I couldn't find an answer to this question. I am trying to set up a link in org-mode that transfers a file from a remote server to my local machine (or vice-versa). According to the manual I have to write something like /scp:user@host:filepathonremotemachine and that's it. No specification of where the file should be moved to, which is weird. I've tried to do it this way and it simply opened the file (as if I was using ssh); tried other combinations also, without any luck. There is a specific reason for why I am trying to do this with tramp and not a shell:command link. Any help is very welcome

UPDATE Apparently TRAMP is less useful than what it promises. That leaves me with the shell:command link option. The problem then revolves around avoiding the openssh window that pops out. The closest solution I found was here and it resumes to setting up an ssh-agent. I am not very familiar with this procedure and I would prefer to use the authinfo.gpg authentication method. Do I have this option? Thanks.

Ajned
  • 523
  • 5
  • 21
  • Although not directly on point, I previously wrote up an example of how to synchronize folders/files with Emacs using rsync taking advantage of the `auth-source` built-in package so that a user does not need to key in user id or password every time; and, there is also a local example where authentication is not needed (e.g., a trusted home network): https://emacs.stackexchange.com/a/5844/2287 Perhaps there is something in there which might inspire you to create your own solution. My recollection is that Emacs 24 had a bug preventing the example from working correctly, so use Emacs 25+. – lawlist Feb 25 '18 at 18:30
  • Thanks for the input. I am not as concerned with having to put the password every time. My main problem is that tramp seems unable to copy or synchronize files with a remote server, which is absurd, because it is such a standard operation. I will have a look at your example and post here if I find a solution. – Ajned Feb 26 '18 at 10:20
  • A `shell:command` link is exactly what you need. What is the specific reason that you don't want to do that? Tramp is a remote access mechanism: it just opens a (remote) file as if it were local or saves a buffer remotely as if the file you save to were local: nothing more. – NickD Feb 26 '18 at 15:20
  • I see. I guess I gave too much credit to Tramp. I will use the shell:command approach then. The reason why I didn't want to use a shell link is that I want to use authinfo.gpg authentication and I couldn't get it to work with that type of link. Specifically, emacs opened an external openssh window, instead of referring to the authinfo.gpg file for a relevant entry. – Ajned Feb 26 '18 at 16:54
  • 1
    Not to start a fight, but tramp is *very* useful and it promises nothing more than what it delivers. You might have *assumed* that it promises something more but that is *your* mistake, not tramp's. – NickD Feb 27 '18 at 18:46

2 Answers2

3

Tramp itself offers just alternative implementations of native Emeacs functions. In this sense, it is dumb, as every library, because it doesn't know what the caller wants.

I'm not an org-mode specialist, but could you please show, which kind of link you have in mind? Without any remoteness, just a link which copies a file locally. Replacing local file names with remote ones will be easy then.

I assume, you need something like an external link, evaluating Lisp code. Like

 elisp:(copy-file "/path/src" "/path/target")
Michael Albinus
  • 1,571
  • 9
  • 19
  • 1
    Adding here the code to copy "to" and "from" a server just for completeness sake `elisp:(copy-file "/path/src" "/scp:user@host#port:/path/target")` and `elisp:(copy-file "/scp:user@host#port:/path/src" "/path/target")` – Ajned Feb 28 '18 at 09:09
  • I would also add that the optional field of the copy-file function: OK-IF-ALREADY-EXISTS should be set to non nil, since otherwise the copied file will not be transferred. – Ajned May 06 '18 at 15:33
  • Another detail is that as mentioned in this [Github post](https://github.com/emacs-helm/helm/issues/1945) scp does not work for some emacs/tramp versions. Therefore it is preferable to stick with ssh instead. – Ajned Jan 21 '19 at 21:30
1

The following works (for some definition of "works"):

* link to copy a file

[[shell:scp remote.host.com:/path/to/file /tmp][scp]]

But you must have arranged for passwordless login to the remote host beforehand (e.g. ssh-copy-id your public key to the remote): given that, there is no output in the org buffer, no openssh popup, just the standard question from org-mode asking if you really want to execute the shell command and the file is copied quietly to its destination.

NickD
  • 5,937
  • 1
  • 21
  • 38
  • So there is really no way to have a password prompt at the terminal bar of emacs instead? :-( – Ajned Feb 27 '18 at 19:38
  • 1
    Try Michael Albinus's answer: `[[elisp:(copy-file "/scp:user@remote:/path/to/file" "/tmp")][scp]]` – NickD Feb 27 '18 at 21:59
  • I couldn't see it if you hadn't told me. Thank you so much. My question had such an obvious answer: "This is emacs. There is always a way" :-). Many regards. – Ajned Feb 28 '18 at 09:06