terrychou / iVim

A vim port to iOS.
601 stars 34 forks source link

scp seems to execute curl #197

Open anjiro opened 3 years ago

anjiro commented 3 years ago

When I run !scp user@host file . I see the curl progress indicator followed by an error message. Depending on whether the remote host has vim's SSH key, either curl (67) authentication failure or curl (79) failed to recv file.

This problem also manifests when trying to edit a remote file (:e scp://...); there are no errors, but the file is always empty and changes are never written to the remote.

terrychou commented 3 years ago

Right now, command scp is a wrapper around curl.

As to the remote editing problem, it may have something to do with the authentication. You can refer to https://github.com/terrychou/iVim/wiki/External-Command:-ssh for some details.

anjiro commented 3 years ago

Yes, I followed those instructions and authentication seems to work; for example, netrw can list directory contents and I can run :!ssh user@host without being asked for a password. But the problems above happen even so.

anjiro commented 3 years ago

I've figured out the issue. Regular scp defaults to paths relative to the home directory; that is, scp user@host:file.txt will get file.txt from user's home directory. But curl assumes paths relative to root, so curl -u user: scp://host/file.txt will try to get file.txt from /. Instead, you have to use curl -u user: scp://host/~/file.txt.

When using netrw to browse a directory via :e scp://user@host/, it correctly lists buser's home directory, but when selecting a file to edit, the call to curl doesn't include the ~ (probably because netrw is expecting stock scp rather than curl), so the result is an empty file. The same issue likely is happening on the write-side.

terrychou commented 3 years ago

Yes, you are right. It behaves like this is right because of the curl wrapping implementation.