What controls open network connections, Windows and Linux. lazarus / 21-General ---------------------------------------------------------------------- marsheng · 2022-03-29 20:17 A work around in windows is to map a network drive to a drive letter and then it can be found with SheelTreeView or open dialog.  I haven't found anything similar with Linux. Does lazarus have an Network viewer control for either OS ?  It looks like the OS handle them quite differently. ---------------------------------------------------------------------- Warfley · 2022-03-30 08:36 What do you mean by open network connections. What windows shows you here are devices that provide access through some protocols windows knows (like SMB). These aren't like open connections, these are just devices in the network with certain ports open. If you want to get this on linux check out NMap ---------------------------------------------------------------------- MarkMLl · 2022-03-30 08:40 Quote from: Warfley on March 30, 2022, 10:36:56 amWhat do you mean by open network connections. What windows shows you here are devices that provide access through some protocols windows knows (like SMB). These aren't like open connections, these are just devices in the network with certain ports open. If you want to get this on linux check out NMap I see what he's getting at, but the truth of the matter is that desktop environments go to a great deal of trouble to accommodate multiple protocols- e.g. SMB, NFS and FISH- and I suspect there's no simple answer. MarkMLl ---------------------------------------------------------------------- PierceNg · 2022-03-30 09:39 Quote from: marsheng on March 29, 2022, 10:17:27 pmA work around in windows is to map a network drive to a drive letter and then it can be found with SheelTreeView or open dialog.  I haven't found anything similar with Linux. Linux has no drive letters. Filesystems (what we think of as drive E, drive F, etc in Windows) are mapped under the root directory "/". By convention temporary mounts done manually are mounted at /mnt. On desktop Ubuntu, automated mounts, such as when I plug in a USB drive, go under /media//; other desktop Linux may have other conventions. ---------------------------------------------------------------------- dbannon · 2022-03-30 09:48 I wonder if the OP is referring to the way things on Linux get mapped via, for example, gvfs ?  I have a SMB share that shows up beautifully in my Caja file browser but looks like this if I want to find it in an application (such as in a LCL FileOpenDialog) - Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i /run/user/1000/gvfs/smb-share\:server\=greybox\,share\=store2/ And thats quite messy and quite difficult to tell an end user where to go searching .... Davo ---------------------------------------------------------------------- MarkMLl · 2022-03-30 10:04 Quote from: PierceNg on March 30, 2022, 11:39:03 amBy convention temporary mounts done manually are mounted at /mnt. On desktop Ubuntu, automated mounts, such as when I plug in a USB drive, go under /media//; other desktop Linux may have other conventions. It varies. I'm reasonably confident that temporary mounts under /media will work for most Debian derivatives, but I've seen systems which mount stuff under rather than at /mnt and getting that wrong would cause major grief. I think the bottom line is that OP is used to a graphical presentation, and that the various desktop environments- irrespective of base OS- present e.g. a newly-hotplugged USB drive as an item in a pane rather than as a node in a tree. MarkMLl ---------------------------------------------------------------------- Warfley · 2022-03-30 11:33 And then you get to users like me, who simply mount everything into their home directory For finding mount points on linux the best option is to use the mount or df utility, or by reading the /proc pseudofiles mounts and mountsinfo. More information can be found here: https://linoxide.com/list-mounted- drives-on-linux/ The problem is that under linux mounting directories into the file system is very common, not just network mounts, so this list needs to be filtered. But that said, in the original post, the thread creator showed (in the screen shot) the network section of windows shell tree view. These are not mounted drives, but are the results of windows actively searching servers in the local network that *could* be connected to, but not necessarily are mounted (e.g. this shows other PCs in the network, even though you require their login data to access their shared files). So this is something that linux simply does not do. This is why I origninally talked about using NMap for this ---------------------------------------------------------------------- MarkMLl · 2022-03-30 11:40 Quote from: Warfley on March 30, 2022, 01:33:19 pmFor finding mount points on linux the best option is to use the mount or df utility, or by reading the /proc pseudofiles mounts and mountsinfo. More information can be found here: https://linoxide.com/list-mounted- drives-on-linux/ The problem is that under linux mounting directories into the file system is very common, not just network mounts, so this list needs to be filtered. And that's increasingly true with more and more temporary filesystems set up by systemd et al. Another extremely useful utility is lsblk. MarkMLl ---------------------------------------------------------------------- dbannon · 2022-03-30 23:08 No guys, I think you are missing the question. The OP wants a control to view potential or real mounts, in the same way that Linux File Managers allow you to browse "network drives", choose the one you want to look at graphically.  I imagine that he/she would like to see network shares in, for example, a TOpenDialog. (Hmm, so would I) As noted above, the File Managers's GVFS helpers use obscure mount points under /media or /run and while its possible to browse to them using eg TOpenDialog its not obvious. This was not always the case, some years ago, before Desktops standardised on GVFS, you could often see a share in the LCL's file/directory dialogs. I wonder if we could call GVFS from LCL to get that information cleanly ? As far as using mount, lsblk etc, come on, we are looking for a GUI solution that shows shares of interest to the user. Not snaps (turns, spits on ground), cgroups etc. So yes, I agree with the user, a 'control' that shows shares is needed. Maybe a option to TOpenDialog and its friends ? Davo ---------------------------------------------------------------------- dbannon · 2022-03-31 01:23 OK, I lie ! I just tested what I was going on about above and it works fine on three out of three (linux) systems. So, as long as you have an existing connection, ie a SMB or usb key plugged in, they show up fine in the TOpenDialogs. This is clearly something that has been fixed in the last year or so. Its a while since I tested it (and grizzled about it). I can now remove a whole lot of needlessly complicated user instructions ! But what is missing is the ability to initial make that (eg) SMB connection and that may well be the control the OP is wishing for. A GVFS thing .... Davo ---------------------------------------------------------------------- PascalDragon · 2022-03-31 07:26 Quote from: dbannon on March 31, 2022, 01:08:04 amThis was not always the case, some years ago, before Desktops standardised on GVFS, you could often see a share in the LCL's file/directory dialogs. I would hardly call GVFS standard, when it isn't used by e.g. KDE which uses KIO instead. ---------------------------------------------------------------------- marsheng · 2022-03-31 22:19 Thanks for the replies. Makes good reading. >> The OP wants a control to view potential or real mounts, in the same way that Linux File Managers allow you to browse "network drives"  **************  Exactly Maybe there is another way to skin a cat. The problem. I have a windows server and several machines around the workshop dumping files to CNC machines. On each CNC machine I have a PC which gets the files from the server. They all run Delphi programs at the moment. On each PC, I map the server drive and then Delphi can find the drive and files I need.  I'm trying to change the PC next to the  CNC to  Linux boxes (PI) and change to Lazarus. So the problem is, how do I find the files on the server using Lazarus controls.  SheelTreeView from what I can see, cannot access my server files.  It only works locally. Is there another way or control to use? It would be great if I could 'map' ShellTreeView to a server directory or remote drive. PS My understanding of Linux core os is limited. ---------------------------------------------------------------------- dbannon · 2022-03-31 23:22 marsheng , there are two sides to this (important you see the difference) - 1. Making the connection between the local compter and the file server, in Unix speak, 'mounting'. 2. Showing files on that connected file server in a GUI component. The first one, as far as I know is not handled by any component in in LCL. You could code it up easily enough using FPC's ability to execute command lines. The second one ?  Well, as I demonstrated to my embarrassment above, LCL components such as TOpenDialog do show shares that have been mounted. I have not used ShellTreeView. Have you tried using ShellTreeView after you have mounted a share ?  If it does not work, then I guess it could be treated as a bug but its probably a case of no one has added the necessary code yet. I am sure it could be done.  I'd be looking in the code of TOpenDialog to see how it extends its reach to those shares if I was you. Alternatively, easier, you could use, directly, TOpenDialog and then FindFirst/FindNext and put the results into a eg TListVist, effectively making your own ShellTreeView. Thats how I work. Getting back to Point One, how you would programmatically mount a share will depend on what sort of share it is, SMB, NFS, USB drive etc ?  I'd guess SMB, so you will end up calling a command line involving the smbclient program. If you can assume pre knowledge of what the server and the share are called, thats pretty easy. If you need to need to search for a likely network share, somewhat harder. If you can instruct the end user to mount the share before using your app, its a "no issue". Davo EDIT: OK, just had a brief play with TShellTreeView and TShellListView. As you indicated, TShellTreeView does not show you mounted shares as "shares", but you can browse to eg /run/user/1000/gvfs/mysambashare and so view the files in it in the TShellListView.  I suggest if you require your users to do that, they will hate you ! ---------------------------------------------------------------------- marsheng · 2022-04-01 01:50 Thanks dbannon, I think I have enough to go forward on now. I am saving the last used directory to an INI when I open a file so at least  /run/user/1000/gvfs/mysambashare or what ever will be reloaded next time I run the program and will be in the right place. I've just googled map vers mount and see the difference.  After all my windows complaints, I'll give it a +1 for mapping. From the outside, Linux looks excellent,  everything just works, wireless, speakers etc, but, once inside the number of files and directories etc it seems a mess. Not even sure how to sort files and directories into alphabetical order. I'll leave that for another day. ---------------------------------------------------------------------- marsheng · 2022-04-02 14:19 I've attached 2 screen shots using OpenDialog. Windows shows network drives but Linux not. I'm running the standard LinuxMint 20. So how do I access network files from within Lazarus ? ---------------------------------------------------------------------- MarkMLl · 2022-04-02 14:28 Quote from: marsheng on April 02, 2022, 04:19:18 pmI've attached 2 screen shots using OpenDialog. Windows shows network drives but Linux not. I'm running the standard LinuxMint 20. So how do I access network files from within Lazarus ? What protocol are they made available by, and where are they mounted? MarkMLl ---------------------------------------------------------------------- marsheng · 2022-04-02 14:52 I'm new to Linux. I've used samba in the past to connect machines, but I'm not sure what Mint uses as default. If I use Mint's file explorer and connect to a network drive, then OpenDialog finds the mapping. See attached.  So it looks like I will need to add something on boot to add this mapping. Still, it looks like browse network is not an option from withing Lazarus. ---------------------------------------------------------------------- PascalDragon · 2022-04-02 18:51 Quote from: marsheng on April 02, 2022, 04:52:39 pmStill, it looks like browse network is not an option from withing Lazarus. This has nothing to do with Lazarus. The dialogs are provided by the widget set and if neither Qt nor GTK provide direct access to mounted network drives then you're simply out of luck. The design philosophy of Windows and Linux is simply different in that regard. ---------------------------------------------------------------------- MarkMLl · 2022-04-02 19:57 Quote from: PascalDragon on April 02, 2022, 08:51:58 pmThis has nothing to do with Lazarus. The dialogs are provided by the widget set and if neither Qt nor GTK provide direct access to mounted network drives then you're simply out of luck. The design philosophy of Windows and Linux is simply different in that regard. I don't think it's possible to dismiss it that brusquely. Now I grant that the typical desktop file management app has plugins etc. that are tailored for specific network protocols, but I've just enabled NFS access to a remote share in my fstab and Lazarus's "File Open" dialog(u)e now shows the name of the remote system in the "Places" pane... twice, in actual fact, with an "operation permitted for root only" error when one (but not the other) is clicked on. If I go to Firefox's "Open File", I see the remote system's name once and clicking on it shows the available files. I've not really explored the SMB (Samba) situation since OP's vague as to what he's using. Lazarus 2.2.0 gtk2, Debian 10, x86_64 KDE desktop. Next day: the duplicated remote name has disappeared, leaving only the one that complains about no root privilege. Lazarus built for Qt doesn't have anything equivalent in the dialogue. MarkMLl ---------------------------------------------------------------------- dbannon · 2022-04-02 23:02 Quote from: marsheng on April 02, 2022, 04:52:39 pmIf I use Mint's file explorer and connect to a network drive, then OpenDialog finds the mapping. See attached.  marsheng, that is what I explained to you a couple of days ago. If the network drive has been mounted, TOpenDialog finds it.  If its not mounted, it does not exist as a file system on the system and therefore cannot be found by TOpenDialog and friends. I explained to you that you can search for and mount a drive in your own code but that will involve writing some code. Or you establish the connection before opening your app. By the way, its not a case of what eg Linux Mint uses as a default connection, the protocol to be used is established by the server. My guess is you have a 'server', probably a Windows box, that is offering a "windows file share", that means its SMB. The tool you need to use, as I mentioned, is smbclient. This is not a LCL bug, its more something that LCL does not do. It would be good if it did offer you a component that does it but no one has been sufficiently motivated to write one yet. Maybe you, with the need, will write one ?  Thats how OpenSource works. @PascalDragon - the TOpenDialog family do provide access to mounted file systems, the OP wants the tools to find and mount a remote FS that is currently unmounted. As I mentioned, it could be implemented with a "network" button or link that would scan, using nominated protocols, the local network, offer the user a list and then get required credentials and mount, using either GVFS, smbclient, whatever KDE uses, etc. Davo ---------------------------------------------------------------------- marsheng · 2022-04-02 23:22 >> If the network drive has been mounted, TOpenDialog finds it. Quite correct, but being new to Linux, I'm still finding my way. I didn't mount the drive, file explorer did it for me. This is quite different to windows where you perform map network drive. It is an operation I chose to do.  So my next step is to find how to mount drive on boot. Should not be to difficult. Thanks Wallace. ---------------------------------------------------------------------- MarkMLl · 2022-04-03 06:35 Quote from: marsheng on April 03, 2022, 01:22:47 amQuite correct, but being new to Linux, I'm still finding my way. I didn't mount the drive, file explorer did it for me. It is not "File Explorer", generally speaking there is no such thing on Linux. It is some part of your desktop environment, and the details will vary by distro (and it is fairly common for systems to allow the user to select which one he wants at login). And the remote filesystem is not necessarily mounted, some desktop environments access remote resources directly. If the remote filesystem is /not/ mounted, then it's unreasonable to expect Lazarus or apps built using the LCL etc. to see it. It's also unreasonable to expect an arbitrary program to control mounts or unmounts: unix is more restrictive of this than Windows. So it's really down to you to find your way around your system. But I also must emphasise that you need to read all questions and suggestions once you've started a topic: earlier messages give you some useful hints which I suspect you've not really absorbed. MarkMLl ---------------------------------------------------------------------- Warfley · 2022-04-03 11:50 Quote from: marsheng on April 03, 2022, 01:22:47 amSo my next step is to find how to mount drive on boot. Should not be to difficult. How to mount an SMB share: https://linoxide.com/howto-mount-smb- filesystem-using-etcfstab/ Code: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i mount -t cifs -o vers=1.0,username=user_name //server_name/share_name /mnt/dataNote that the website say you should use sud (i.e. sudo mount ...) but because you are going to execute this on the startup, it will be executed as root anyway, so no need for sudo For running a script/command on startup, there are multiple ways to do so on linux, see https://www.simplified.guide/linux/automatically-run- program-on-startup#automatically-run-program-on-linux-startup-via- systemd For you relevant are only the first 3 methods, as the other ones are not executed on boot but rather on user login/creation of the user shell. The third option System V rc.local is probably the easiest, but I don't know how wide the support for this still is, as most Linux distros are using systemd. The first option systemd is probably the "intendet" way for most linux distros, as most linux distros are based on systemd, but it is also the most complicated one (as systemd always makes things more complicated). I personally would go with the second method the cron job, because it does not rely on your distro being systemd or sytem V, but only requires cron to be installed and is also very easy to do PS: if you want to search or lookup the SMB shares in your network, see this: https://superuser.com/questions/1492010/finding-all-samba- shares-in-local-network ---------------------------------------------------------------------- dbannon · 2022-04-03 23:28 Quote from: Warfley on April 03, 2022, 01:50:46 pmCode: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i mount -t cifs -o vers=1.0,username=user_name //server_name/share_name /mnt/data I thought Linux does not support SMB 1.0 any more because of security concerns ?  I am away from home now and away from any SMB shares so cannot test... Davo ---------------------------------------------------------------------- dsiders · 2022-04-04 06:46 Quote from: dbannon on April 04, 2022, 01:28:08 amQuote from: Warfley on April 03, 2022, 01:50:46 pmCode: Bash  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i mount -t cifs -o vers=1.0,username=user_name //server_name/share_name /mnt/data I thought Linux does not support SMB 1.0 any more because of security concerns ?  I am away from home now and away from any SMB shares so cannot test... Davo Samba 4.11 dropped it. Microsoft dropped it for Windows 10. ---------------------------------------------------------------------- PascalDragon · 2022-04-04 11:31 Quote from: dbannon on April 03, 2022, 01:02:46 am@PascalDragon - the TOpenDialog family do provide access to mounted file systems, the OP wants the tools to find and mount a remote FS that is currently unmounted. I'm aware. The point is that it's not part of the LCL's control whether the open dialog provided by the widgetset is able to display mounted network drives (for example it might only display mounted local drives separately) or whether the dialog would be able to display unmounted, but discovered network shares. ---------------------------------------------------------------------- MarkMLl · 2022-04-04 12:43 Quote from: PascalDragon on April 04, 2022, 01:31:36 pm[quote author=dbannon link=topic=58913.msg439407#msg439407 date=16489405 I'm aware. The point is that it's not part of the LCL's control whether the open dialog provided by the widgetset is able to display mounted network drives (for example it might only display mounted local drives separately) or whether the dialog would be able to display unmounted, but discovered network shares. So far, it looks as though the gtk2 widget lists any server that has a mountpoint in /etc/fstab, irrespective of whether there's a live session to it. The Qt dialog(u)e doesn't have the equivalent pane. I'd be surprised if GTK was prepared to get directly involved in setting up shares because (a) in the general case it involves elevated permissions and (b) GTK- as an architectural decision- flatly refuses to cooperate with setuid-root etc. programs. So I think OP's out of luck as far as setting up new connections is concerned. But I'd expect the LCL and Firefox file open dialogues to behave similarly, i.e. show the content of mapped shares. I'm taking a bit of a prod at this from a user's perspective, since it raises a few questions that I need to be able to answer. MarkMLl ---------------------------------------------------------------------- dbannon · 2022-04-05 00:00 Quote from: MarkMLl on April 04, 2022, 02:43:58 pm... I'd be surprised if GTK was prepared to get directly involved in setting up shares because (a) in the general case it involves elevated permissions and (b) GTK- as an architectural decision- flatly refuses to cooperate with setuid-root etc. programs. Well, GVFS is a close friend of GTK and is the tool of choice for most (but not all) distros to "network enable" their file managers. KDE/Plasma based ones being the notable exception.  Its seems to me that it would be possible to call gvfs methods but we'd have to also cover KIO. And the sensible place for it to appear is in the TOpenDialogs. So, when you think of it like that, it does sound a lot like it should be a OS widget set responsibility. EDIT: removed silly question about QT doing a better job, it does not. Davo ---------------------------------------------------------------------- MarkMLl · 2022-04-07 10:37 Quote from: MarkMLl on April 04, 2022, 02:43:58 pmI'm taking a bit of a prod at this from a user's perspective, since it raises a few questions that I need to be able to answer. I had to refresh my memory about working with shared files, in particular SMB tends to be a bit of a moving target. Working on a Linux client with a Linux server, remote directories already mounted using either SMB (v2.0) or NFS (v4) show up correctly in the gtk2 "Places" pane (i.e. with a name from /stc/fstab rather than just as a local directory), although I suspect that I might be seeing the NFS-mounted one also appear as a dummy with no content and that this doesn't time out after a couple of days. There's an obvious gotcha for the inexperienced user in that a drive/directory might appear empty if the name filter at the bottom of the dialog(u)e is only looking for .lpr, .pas and so on Lazarus compiled for Qt5 has no equivalent to the Places pane, but remote directories etc. can be seen by looking at their mountpoints. Other widgetsets, particularly Windows, untested. However I don't think there's a fundamental problem with Lazarus, subject to user expectations as to whether an arbitrary app should be able to set up or tear down shares. MarkMLl