GSConnect / gnome-shell-extension-gsconnect

KDE Connect implementation for GNOME
GNU General Public License v2.0
3.15k stars 255 forks source link

Correct SFTP path is not used for some devices #1610

Open mspatil32 opened 1 year ago

mspatil32 commented 1 year ago

Describe the bug

Hi,

I think the app in phone got updated recently, and I'm getting the below error when trying to access the mounted drive in linux.

Please provide solutions.

image

Steps to reproduce

No response

Expected behavior

No response

GSConnect version

55

Installed from

GNOME Extensions website

GNOME Shell version

No response

Linux distribution/release

No response

Paired device(s)

No response

KDE Connect app version

No response

Plugin(s)

No response

Support log

No response

Screenshots

No response

Notes

No response

f-fouad commented 1 year ago

You don't have permissions to access / of your phone.

Press Ctrl+L and append to the address /storage/emulated/0 to access Android Internal storage. It should be the default.

mspatil32 commented 1 year ago

Hi @f-fouad ,

Thanks for your reply.

Please tell me where should I add the address "/storage/emulated/0".

This issue came up after the "kdeconnect" app got updated yesterday in android. As a work around, I installed the older version of the app (from Jan 2023), and it is working fine.

seanms commented 1 year ago

I'm seeing the same problem after upgrading kdeconnect on my phone.

@mspatil32 When you're on the Nautlius page giving you the error, pressing Ctrl+L opens the address bar at the top. Append "/storage..." to the address.

mspatil32 commented 1 year ago

@seanms Oh okay, understood now. Does this help? Is the entire phone's filesystem accessible by this method? Previously, the Downloads folders in the internal storage was not accessible.

seanms commented 1 year ago

Yes, this appears to work around the problem. I'm able to read and write the phone's file system.

mspatil32 commented 1 year ago

Hi @seanms Thanks a lot. Will try it. Currently, I installed the older version of the app (Jan 2023), and it doesn't give this problem, and I can access some of the folders in the phone (not the main internal storage and the Downloads folder).

alexanderadam commented 1 year ago

I'm seeing the same with recent versions and appending /storage/emulated/0 helps indeed. @andyholmes would it be possible to optionally add this path via settings automatically?

andyholmes commented 1 year ago

No, it's the responsibility of the remote device to report the correct path. This doesn't relate to any settings in GSConnect.

alexanderadam commented 1 year ago

I see. So the KDEConnect client is publishing the remote paths to GSConnect then and currently it is reporting sftp://192.123.123.132:61454/ instead of sftp://192.123.123.132:61454/storage/emulated/0 and hence it is an upstream issue where the KDEConnect client should publish the first valid path instead of the root path.

Do I understand this correctly @andyholmes?

Does anyone know whether there is an upstream ticket for this then?

andyholmes commented 1 year ago

Correct, the remote device must communicate the path. I haven't seen such a bug report yet, nope :/

mspatil32 commented 1 year ago

Hi Will there be an update to kde connect app to solve this issue?

andyholmes commented 1 year ago

You will have to open an upstream bug at https://bugs.kde.org

mspatil32 commented 1 year ago

Sure. Thanks @andyholmes .

alexanderadam commented 1 year ago

Not sure whether it's related but I asked over here. :man_shrugging:

alexanderadam commented 1 year ago

@andyholmes would it be possible just to add a configurable default path in the settings until the issue is fixed in upstream? :pleading_face:

andyholmes commented 1 year ago

No, because it's not a setting. It would be like adding a setting for payload transfer ports, when those should clearly be set internally by the device.

This setting is exposed on the device with the SSH server, because that device has access and control over the server. The remote device can't choose what the correct path is, it can only be told what it is.

ajpy5215 commented 1 year ago

Hi Here are the results of some experiments I have done :

First Configuration :

Second configuration :

Third configuration :

Log extract (slightly modified):

GSConnect: 53 (user) GJS: 16405 Session: x11 OS: Ubuntu 20.04.6 LTS

...

mai 29 18:37:46 org.gnome.Shell.Extensions.GSConnect[24701]: [/service/plugins/sftp.js:_listDirectories/iter</<:160]: SM-A528B: Access denied _listDirectories/iter</<@/home/xxxx/.local/share/gnome-shell/extensions/gsconnect@andyholmes.github.io/service/plugins/sftp.js:160:38

alexanderadam commented 1 year ago

So if KDE Connect works it is likely another issue?

andyholmes commented 1 year ago

@ajpy5215 Thanks for the logs!

The function appears to be a part of a refactoring in #831 which addressed #478. So in fact GSConnect generally ignores the path sent by the Android device and tries to list the directories itself.

This could be fixed by either reverting that patch, or possibly falling back to the advertised paths if the listing fails. Patches for either would be okay by me.

alexanderadam commented 1 year ago

So /storage/emulated/0 is the main storage. How is the path to the external storage then? It seems that /storage/emulated/1 doesn't work.

ajpy5215 commented 1 year ago

I my case I get access to the external Sdcard by appending "storage/635F-151F" to "sftp://192.168.1.24:1739/". Unfortunately the value "635F-151F" is specific to my Android/sdcard combination and will be different in other setups so cannot use that value on your side. I obtained the required value while experimenting with Kubuntu/KDEConnect. I’m not aware of other methods to get that value. Note : appending " sdcard" gives the same result as appending "storage/emulated/0".

alexanderadam commented 1 year ago

I see, thank you!

neural75 commented 1 year ago

Same issue here with ubuntu 23.04. Is there a way to work around this issue? I've tried to bookmark the sftp url on the working /sdcard sub-path but obviously the address and port combination keeps changing, so it won't work for very long. Any other way to create an alias( or something) automatically or from a scripts? (I don't know gvfs very much, whether it has some cmd line tool to list mount points or not, besides the nautilus interface). My problem is that I will likely forget to add /sdcard as the good path (and the emulated thing even more).

neural75 commented 1 year ago

Same issue here with ubuntu 23.04. Is there a way to work around this issue? I've tried to bookmark the sftp url on the working /sdcard sub-path but obviously the address and port combination keeps changing, so it won't work for very long.

I quote myself, I think I've found a simple work-around to share: the mount point is available here: /run/user/1000/gsconnect/by-name/<device name>/sdcard device name is "Mi 9T Pro" in my case, so I bookmarked that path under Nautilus as "Mi 9T Pro sdcard". The path /run/user/1000/gsconnect/by-name/Mi 9T Pro/sdcard seems to be constant and working even when the sftp:// url switches port number.

fjueic commented 10 months ago

hi @andyholmes , I have been messing with source code for a few days. I have an idea for the workaround.

When mounting storage I tried to create a bookmark with the device name which contains soft links representing internal storage and SD card. It seems like resolving network locations takes time leading me to experience a significant speed drop. I dropped this idea.

i saw some Stackoverflow code(can't find the link rn). What it did was, give the location of the nautilus uri of all instances every time it changed. i plan to use that program to monitor D-bus signal and monitor if I open some dummy folders representing the phone's internal storage and sd card. I have the high-level image of how i wil do it.

at the end, it is just a workaround. if such pr i can be accepted, i will try to integrate it into the code. Otherwise, i will write all logic in Python and run a service as I'm comfortable in it as compared to JavaScript.

andyholmes commented 10 months ago

I'm not sure I understand your proposed solution? Nautilus really doesn't know anything about the remote storage, that either has to be sent by kdeconnect-android or queried with GVfs.

fjueic commented 10 months ago

with gvfs we can only mount the location provided by whatever is servering sftp. shortcut are out of option as i mentioned above.

i still cant really find the Stackoverflow link but i have the code

dbus-monitor "
type='signal',
interface='org.freedesktop.DBus.Properties',
path='/org/freedesktop/FileManager1',
member='PropertiesChanged'" |   awk -F '"' '
$2 ~ "^/org/gnome/Nautilus/window/[[:digit:]]+$" {
    window = $2
    sub(".*/", "", window)
    tab = 0
    next
}
window && /string / {
    print window"."++tab": "$2
    next
}
tab {window = 0}'

this will monitor d bus signal PropertiesChanged for file manager and dive output like this image i planned on creating a dummy directory like "device name" inside this "Internal Storage" and "sd card" and whenever i open these, just launch a new instance of nautilus with mapped uri.

andyholmes commented 10 months ago

Ah, yeah that seems out-of-scope for GSConnect. It might make sense as a Nautilus plugin though.

Probably kdeconnect-android should just serve the path to the SD Card if this is an issue though.

fjueic commented 10 months ago

i was checking data shared by kde-connect and it turns out it servers paths for internal storage and sd card. issue lies in with gvfs we can only mount the location provided by whatever is servering sftp.

fjueic commented 10 months ago

kde plasma implements sompthing like kdeconnect:///device-name with internal storage and sd card. And these just redirects to to mapped uri like /storage/emulated/0 and /stoarge/emulated/sdcardvalue. i dont really know anything about custom uri. but i got a workaround(lol)

fjueic commented 10 months ago

@andyholmes please confirm that such PR will not be accepted

andyholmes commented 10 months ago

I would not accept a PR that tries to address issues in GVfs or Nautilus.

The function appears to be a part of a refactoring in #831 which addressed #478. So in fact GSConnect generally ignores the path sent by the Android device and tries to list the directories itself.

This could be fixed by either reverting that patch, or possibly falling back to the advertised paths if the listing fails. Patches for either would be okay by me.

I would accept a PR that did either of these two things.

fjueic commented 9 months ago

If anyone in future is interested in a workaround check this repo. It also handles SD card. i tested in multiple live environment like manjaro, garuda Linux, Pop OS. example

AyushSehrawat commented 8 months ago

Facing same issue on PopOS with gnome 42.9, fixed by appending the path

RushingAlien commented 5 months ago

https://github.com/GSConnect/gnome-shell-extension-gsconnect/issues/1203#issuecomment-1886359637

I've read the KDE Connection Android app code, and I noticed that KDE Connection sends multiple paths, but GSConnect only mounts the root directory; Here:

andyholmes commented 5 months ago

I would not accept a PR that tries to address issues in GVfs or Nautilus.

The function appears to be a part of a refactoring in #831 which addressed #478. So in fact GSConnect generally ignores the path sent by the Android device and tries to list the directories itself. This could be fixed by either reverting that patch, or possibly falling back to the advertised paths if the listing fails. Patches for either would be okay by me.

I would accept a PR that did either of these two things.

nebulosa2007 commented 5 months ago

After investigating exactly what gsconnect-mount-manager does, I found the easiest way to fix the mount path for Nautilus without installing anything.

Steps:

  1. Mount your phone as usual, open the mounted folder in Nautilus and get the error as in the first comment.
  2. Press Ctrl+L and copy the path, e.g. sftp://192.168.1.238:1761/
  3. Edit the Nautilus bookmarks file gedit ~/.config/gtk-3.0/bookmarks
  4. Add a line like sftp://192.168.1.238:1761/storage/emulated/0 MyPhone, save and exit.
  5. MyPhone bookmark in Nautilus should appear, which should open the phone folder without error on click.

This bookmark will only work if the phone has been mounted with GSConnect. To work independently without GSC mount, you need to make a ~/.ssh/config file, where you should specify the ssh connection parameters (In progress...).

fjueic commented 5 months ago

After investigating exactly what gsconnect-mount-manager does

u could have tagged me. gsconnect-mount-manager is a lil thing I wrote when I knew nothing about linux interfaces.

Add a line like sftp://192.168.1.238:1761/storage/emulated/0 MyPhone, save and exit.

what if IP address changes? for me when i change classroom in university. this case is handled in gsconnect-mount-manager

if there are any question regarding the working of gsconnect-mount-manager just ask me or if you want me to explain everything i can do that too

juanmah commented 5 months ago
  1. Add a line like sftp://192.168.1.238:1761/storage/emulated/0 MyPhone, save and exit.

The port is dynamic, and it's changing at each connection.

This bookmark will only work if the phone has been mounted with GSConnect. To work independently without GSC mount, you need to make a ~/.ssh/config file, where you should specify the ssh connection parameters (In progress...).

I'm interested in knowing how to connect without GSC.

fjueic commented 5 months ago

I'm interested in knowing how to connect without GSC.

how I did it before gsconnect-mount-manager

using sshfs with the termux app on Android. I had some python code running in termux and laptop to handle dynamic ip

nebulosa2007 commented 5 months ago

if there are any question regarding the working of gsconnect-mount-manager just ask me or if you want me to explain everything i can do that too

Spent two evenings debugging and now I can say that your mount implementation completely brakes Mount in GSConnect )) After reinstalling gsconnect and deleting service file, GSConnect gives this error:

$ systemctl status --user dbus-:1.2-org.gnome.Shell.Extensions.GSConnect@0.service
....
Apr 05 21:14:11 arch gjs[1285]: JS ERROR: Pixel 4: Gio.IOErrorEnum: Connection failed
                                _promisify/proto[asyncFunc]/</<@resource:///org/gnome/gjs/modules/core/overrides/Gio.js:453:45
                                @/usr/share/gnome-shell/extensions/gsconnect@andyholmes.github.io/service/daemon.js:720:17
                                ### Promise created here: ###
                                _handleMount@/usr/share/gnome-shell/extensions/gsconnect@andyholmes.github.io/service/plugins/sftp.js:231:24
                                async*handlePacket@/usr/share/gnome-shell/extensions/gsconnect@andyholmes.github.io/service/plugins/sftp.js:124:26
                                handlePacket@/usr/share/gnome-shell/extensions/gsconnect@andyholmes.github.io/service/device.js:441:25
                                _readLoop@/usr/share/gnome-shell/extensions/gsconnect@andyholmes.github.io/service/device.js:365:22
                                async*setChannel@/usr/share/gnome-shell/extensions/gsconnect@andyholmes.github.io/service/device.js:346:18
                                _onChannel@/usr/share/gnome-shell/extensions/gsconnect@andyholmes.github.io/service/manager.js:229:20
                                channel@/usr/share/gnome-shell/extensions/gsconnect@andyholmes.github.io/service/core.js:436:19
                                _onIdentity@/usr/share/gnome-shell/extensions/gsconnect@andyholmes.github.io/service/backends/lan.js:390:18
                                async*_onIncomingIdentity@/usr/share/gnome-shell/extensions/gsconnect@andyholmes.github.io/

Any suggestions? May be I need to restore some dconf settings?

fjueic commented 5 months ago

Your mount implementation

Mounting is handled by GSConnect.

What I tried to do was handle the paths.

I will briefly explain what my implementation is doing:

Executing the install script:

On Mounting:

Accessing:

Unmounting:

fjueic commented 5 months ago
  • The install script edits your GSConnect file to add two extra lines of code in sftp.js, both wrapped in try and catch. THAT IS IT, nothing else is edited in your GSConnect installation.
  • If something were to go wrong in my implementation, I don't see it causing any issues with the working of GSConnect.

My main focus was not to interfere with gsconnect working.

Spent two evenings debugging

reinstall the gsconnect to remove those edit two extra lines of code in sftp.js, both wrapped in try and catch.

if this does not fix your issue it's most probably not due to my implementation. I may be completely wrong, so if you can point me to a potential issue I would appreciate it.

nebulosa2007 commented 5 months ago

I may be completely wrong, so if you can point me to a potential issue I would appreciate it.

Found simple solution: rm $HOME/.config/dconf/user Now mounting work as expected but again with wrong path in Nautilus.

Reverting to making proper bookmark, we could use two ways:

Next step: using ~/.ssh/config. In my home network, the phone has a dns name <phonename>.lan, for example pixel-4.lan. Another situation, the phone does not have a dns name, but the router often gives the IP for the phone the same if that phone appears frequently on the wi-fi network. Get the IP or dns of the phone anyway, then:

  1. Add line sftp://pixel-4.lan/storage/emulated/0 Pixel in .config/gtk-3.0/bookmarks
  2. Add options for ssh connection in ~/.ssh/config:
    Host pixel-4.lan
    Port 1739
    User kdeconnect
    IdentityFile ~/.config/gsconnect/private.pem
    IdentitiesOnly yes
    IdentityAgent none
    PubkeyAcceptedKeyTypes ssh-rsa
    HostKeyAlgorithms +ssh-rsa
    ForwardX11 no
    ForwardAgent no
    PermitLocalCommand no
    ClearAllForwardings yes
    Protocol 2
    NoHostAuthenticationForLocalhost yes
    ControlMaster auto
    ControlPath=/run/user/1000/gvfsd-sftp/%C

Nautilus will open the phone folder on click. GSConnect should be loaded in the background, of course.

Coeur-Noir commented 4 months ago

Won't help much but :

⋅ sftp://IP:portA/storage/emulated/0 → seems to be the first user created on Android ; ⋅ sftp://IP:portB/storage/emulated/10 → …the second user.

Because yes, there can be many users on one phone - or many « sessions » for different purposes.

fjueic commented 4 months ago

Won't help much but :

⋅ sftp://IP:portA/storage/emulated/0 → seems to be the first user created on Android ; ⋅ sftp://IP:portB/storage/emulated/10 → …the second user.

i don't think anybody is using multiple user is android

dynamically handled here

Coeur-Noir commented 4 months ago

Well I do that's how I know...

:-D -- Envoyé depuis Motorola g84 via le courrieleur libre K-9 Mail ( prochainement Thunderbird ).

Le 3 mai 2024 11:06:12 GMT+02:00, fjueic @.***> a écrit :

Won't help much but :

⋅ sftp://IP:portA/storage/emulated/0 → seems to be the first user created on Android ; ⋅ sftp://IP:portB/storage/emulated/10 → …the second user.

i don't think anybody is using multiple user is android

dynamically handled here

-- Reply to this email directly or view it on GitHub: https://github.com/GSConnect/gnome-shell-extension-gsconnect/issues/1610#issuecomment-2092604355 You are receiving this because you commented.

Message ID: @.***>

akvedi commented 2 months ago

There is a workaround for this. When gsconnect mounts the sftp it adds a new folder in the /run/user/1000/gvfs with host ip and port as a folder name.

ss

I wrote the below bash script to automatically find the host ip and port from the folder name and then open Nautilus with the correct path.

#!/bin/bash
# A script to open GSconnect sftp folder with correct path

# Define the path to the GVFS folder
gvfs_path="/run/user/1000/gvfs"

# Find the folder that matches the pattern "sftp:host=*,port=*"
folder=$(find "$gvfs_path" -type d -name "sftp:host=*,port=*" | head -n 1)

if [ -z "$folder" ]; then
  echo "No matching folder found."
  exit 1
fi

# Extract host and port from the folder name
regex="sftp:host=([^,]*),port=([0-9]*)"
if [[ $folder =~ $regex ]]; then
  host=${BASH_REMATCH[1]}
  port=${BASH_REMATCH[2]}
else
  echo "Failed to extract host and port from folder name."
  exit 1
fi

# Construct the sftp URL
sftp_url="sftp://$host:$port/storage/emulated/0"

echo "Opening $sftp_url in Nautilus..."

# Open the sftp URL in Nautilus
nautilus "$sftp_url" &


This script works with Nautilus but can be easily modified to work with other file managers.