INSTALL SAMBA ON UBUNTU & TRANSFER MOODLE FILES

https://help.ubuntu.com/community/How%20to%20Create%20a%20Network%20Share%20Via%20Samba%20Via%20CLI%20(Command-line%20interface/Linux%20Terminal)%20-%20Uncomplicated,%20Simple%20and%20Brief%20Way!

Samba Server: Moodle Prod Server – 1.1.1.37
Samba Client: Moodle Dev Server – 1.1.1.51

In our scenario, we want to transfer files from dev to prod

Samba Server

1- open moodle prod server and install samba server

$ ssh -l msen 1.1.1.37
$ sudo apt-get update
$ sudo apt-get install samba

2- set samba password for machine user msen

$ sudo smbpasswd -a msen

Samba passwords are stored in /etc/samba/smbpasswd

3- Create a directory called moodle to be shared

$ sudo mkdir /home/msen/moodle
$ sudo chmod -R 777 /home/msen/moodle

4- Make a safe backup copy of the original smb.conf file to your home folder, in case you make an error

$ sudo cp /etc/samba/smb.conf ~

5- Edit the smb.conf file

$ sudo nano /etc/samba/smb.conf

Once “smb.conf” has loaded, add this to the very end of the file

 [moodle]
 path = /home/msen/moodle
 available = yes
 valid users = msen
 read only = no
 browseable = yes
 public = yes
 writable = yes

6- Restart the samba

$ sudo service smbd restart

7- Once Samba has restarted, use this command to check your smb.conf for any syntax errors

$ testparm


 

Samba Client

1- Open moodle dev server and install samba client

$ ssh -l msen 1.1.1.51
$ sudo apt-get install smbclient

2- make sure the samba 139 and 445 ports of samba work

$ sudo iptables -S

if not there,

$ sudo iptables -L –line-numbers

delete the drop line

$ sudo iptables -D INPUT 6
$ sudo iptables -A INPUT -p tcp –dport 139 -j ACCEPT
$ sudo iptables -A INPUT -p tcp –dport 445 -j ACCEPT

now add back the drop line

$ sudo iptables -A INPUT -j DROP

3- List all shares

$ smbclient -L //1.1.1.37/moodle -U msen

 Enter msen's password:
 Domain=[WORKGROUP] OS=[Unix] Server=[Samba 4.1.11-Ubuntu]
 Sharename Type Comment
 --------- ---- -------
 IPC$ IPC IPC Service (online server (Samba, Ubuntu))
 moodle Disk
 print$ Disk Printer Drivers
 Domain=[WORKGROUP] OS=[Unix] Server=[Samba 4.1.11-Ubuntu]
 Server Comment
 --------- -------
 ONLINE online server (Samba, Ubuntu)
 Workgroup Master
 --------- -------
 WORKGROUP ONLINE

4- Let’s transfer moodle files. Make sure you are under the /opt/moodle/

Go to under client’s directory where you want to transfer your files from

$ cd /opt/moodle

Connect Samba

$ smbclient //1.1.1.37/moodle -U msen
smb: \> recurse
smb: \> prompt
smb: \> mput *

mput *  puts all the files from client’s /opt/moodle directory into server’s /home/msen/moodle directory

https://www.linux-tips.org/article/47/recursively-mput-with-smbclient 
 By default recurse option is OFF. Entering recurse command on the smb prompt will toggle this option to ON, and similarly prompt option is ON by default. Entering prompt option will toggle this option to OFF, so that smbclient will not ask confirmation for each file in the subdirectories. mput will put multiple files matching trunk* pattern on the local filesystem.

Other Samba Commands
http://www.computerhope.com/unix/smbclien.htm

 

To exit Ctr+C

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s