Accessing Windows Shares from the Linux Command Line

  

The Samba Project is an open source project that supports Linux, UNIX, and other UNIX-like operating systems
and Windows
interoperability. Samba is included in most Linux distributions and is typically installed and configured to support Linux systems to join and interoperate with an existing Windows® workgroup or domain, often as a Common Internet File System (CIFS) file server for use by Windows
systems. The Samba 4.x installation also allows the Samba server to act as an Active Directory Domain Service controller and an integrated Domain Name System for the Windows
domain.

Although the Samba server provides an excellent mechanism for providing Linux resources from Windows systems, allowing Linux systems to print to Windows printers, if you are only interested in occasionally retrieving files from WIndows shares, install and configure Samba. The server may be overkill. The Samba client package (samba-client) contains several utilities designed for this type of occasional interaction, including the smbclient application, which provides an interactive command line interface (CLI) for remote access to Windows shares.

If you are unsure of the share name provided on the remote Windows server, you can use the smbclient application to query a server and type the -L option after the server's name or IP address to list the available resources on that server. As shown in Listing 1.

Listing 1. Listing Windows server resources using smbclient

$ smbclient -U barlowliu -L Barlow-pcEnter barlowliu's password:Domain=[CKING] OS=[Windows 7 Professional 7601 Service Pack 1 ] Server=[Windows 7 Professional 6.1]

Sharename Type Comment--------- -----------ADMIN$ Disk Remote Management C$ Disk Default Share D$ Disk Default Share E$ Disk Default Share F$ Disk Default Share IPC$ IPC Remote IPCsoft DiskDomain=[CKING] OS=[Windows 7 Professional 7601 Service Pack 1] Server=[Windows 7 Professional 6.1]

Server Comment --------- -------BARLOW-PC

Workgroup Master--------- -------CKING BARLOW-PCMSHOME PC-20100408VZXVWORKGROUP CKINGACC

Note: -U specifies the username for remote login, and -L specifies the Windows server.

After determining the name of the share you wish to connect to (such as the soft share above), you can use the smbclient application to connect to a specific share to check or retrieve the file, as shown in Listing 2.

Listing 2. Retrieving files from a Windows share using smbclient

$ smbclient -U barlowliu //barlow-pc/softEnter barlowliu's password:Domain=[CKING] OS=[Windows 7 Professional 7601 Service Pack 1] Server=[Windows 7 Professional 6.1]smb: \\> ls. D 0 Wed Mar 27 10:01:01 2013.. D 0 Wed Mar 27 10:01:01 2013OS D 0 Sat Apr 27 17: 13:50 2013 Office Software D 0 Wed Mar 27 14:11:32 2013 Instant Messaging D 0 Wed Mar 27 09:53:40 2013 Database D 0 Mon Jun 3 08:59:15 2013 Browser D 0 Wed Mar 27 09 :53:59 2013 system tools D 0 Wed Apr 24 15:24:18 2013

37501 blocks of size 4194304. 21943 blocks available

smb: \\> cd system tools smb: \\ System Tools\\> ls. D 0 Wed Apr 24 15:24:18 2013.. D 0 Wed Apr 24 15:24:18 2013Dell Server Software D 0 Wed Apr 24 14:22:40 2013Hypertrm D 0 Thu Mar 28 14 :53:33 2013NSCP-0.4.1.90-x64.msi A 29418492 Sun Apr 7 17:19:56 2013putty D 0 Wed Mar 27 09:27:36 2013vnc-4_1_3-x86_win32.exe A 741744 Wed Oct 15 17:14: 08 2008Windows Loader v2.2.1 D 0 Tue Jan 29 14:33:00 2013

37501 blocks of size 4194304. 21943 blocks availablesmb:\\system tools\\> get NSCP-0.4.1.90-x64.msigetting file \\system tools\\NSCP-0.4.1.90-x64.msi of size 29418492 As NSCP-0.4.1.90-x64.msi (836.7 KiloBytes/sec) (average 836.7 KiloBytes/sec)

The example in Listing 2 shows that smbclient provides a CLI to connect to a remote server. This interface supports familiar Linux commands such as cd (for moving in a directory on a remote server) and ls (for listing the contents of a given directory). Once you find the file you want to retrieve, you can retrieve it using the get command and store it in the directory where you want to execute smbclient . To store the retrieved files in another directory, use the lcd (local change directory) command to change the directory that smbclient considers to be the current directory.

If you only need to occasionally access one or more files in a Windows share, and don't care about using a file manager (such as Gigolo, GNOME Nautilus, KDE Dolphin, Konqueror, or Thunar) to graphically browse Windows shares , then you can safely use the smbclient application. The smbclient application enables a remote share to be used in the context of the application, not in your entire system. To browse a Windows share and make it available to the application of your choice, you must mount the share to your system in the same way that you mount the local file system.

Copyright © Windows knowledge All Rights Reserved