How to `ls` a remote folder?

10

1

This one uses Samba:

 $ ls smb://192.168.5.4/wdtvlivehub/abc
 ls: cannot access smb://192.168.5.4/wdtvlivehub/abc: No such file or directory

I somehow managed to do it by;

  1. Browsing to the remote directory. (pcmanfm 0.9.9)
  2. Opening the current folder in a terminal.
  3. Executing pwd to get /home/myuser/.gvfs/wdtvlivehub on 192.168.5.4
  4. Doing ls /home/myuser/.gvfs/wdtvlivehub on 192.168.5.4 worked.

..What would be a more elegant way?

octosquidopus

Posted 2011-09-18T21:03:20.283

Reputation: 826

Is mounting the remote filesystem an option? – beatgammit – 2011-09-18T21:05:24.443

Yep, it can be. – octosquidopus – 2011-09-18T21:15:59.003

Answers

5

Your current method of using ~/.gvfs/ is fine, but you don't need pcmanfm for that – you can use gvfs-mount to connect to the share. Additionally, tools such as gvfs-ls and gvfs-cp will accept your smb:// URI.

$ gvfs-mount smb://HOST/SHARE/

$ gvfs-ls smb://HOST/SHARE/

In recent gvfs versions the location is $XDG_RUNTIME_DIR/gvfs/ (aka /run/user/$UID/gvfs/), and the subdirectory names have become more machine-readable:

$ ls /run/user/$UID/gvfs/smb-share:server=HOST,share=SHARE/

In older versions:

$ ls ~/.gvfs/"SHARE on HOST"/

(Remember to quote spaces within path names.)


Specifically for Samba, you can use the smbclient program, or mount the share on the VFS layer by using mount -t cifs. (The latter is, unfortunately, limited to root.)

$ smbclient //host/share

# mount -t cifs //host/share /mnt

(For other kinds of filesystems, such as SFTP and FTP, sshfs and curlftpfs exist respectively.)

user1686

Posted 2011-09-18T21:03:20.283

Reputation: 283 655

It's worth clarifying that "gvfs-ls smb://host/share/" works as described without the need to mount the drive using gvfs-mount first. In other words, the commands in the first code block don’t all need to be used to achieve your desired outcome. – John T – 2016-02-18T06:50:09.000

@JohnT: Must have been a coincidence. I usually get The specified location is not mounted. – user1686 – 2016-02-18T11:47:33.863

@grawity - I've usually already browsed to the location in Nautilus or similar and authenticated that way, that might have something to do with it. – John T – 2016-02-18T11:50:03.323

@JohnT: Yes, Nautilus uses the same GVFS, and GTK automatically mounts gvfs locations you're trying to access. If the share shows up in Nautilus' side pane, then it is 'mounted' right now. – user1686 – 2016-02-18T11:55:02.383

I mentioned pcmanfm because that is most probably how I will get to the folder before executing it with the script. gv-ls seems to be exactly what I was looking for, though. Looks like it could even replace ls for local directories for the sake of consistency. – octosquidopus – 2011-09-18T21:28:48.650

12

You can use the command smbclient, e.g.:

smbclient -N //192.168.5.4/wdtvlivehub/abc -c ls

rumpel

Posted 2011-09-18T21:03:20.283

Reputation: 231

4Great, but how can I achieve the same output as with regular ls (no columns nor formatting, just a list of files)? It's important because I want to pipe the output to another command. – octosquidopus – 2011-09-18T21:20:50.277