Build Home NAS(2)SmbClient SFTP FTP

Build Home NAS(2)SmbClient SFTP FTP

1. SmbClient
Try with the smbclient on that server
> smbclient //localhost/sillycat-nas -b 8192 -c "put README.md" -U sillycat
Enter sillycat's password:
Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.6.6]
putting file README.md as \README.md (0.6 kb/s) (average 0.6 kb/s)

But I fail to connect that from outside the internal network. I will try forwarding other ports later.
135,137-139, and 445

It seems that samba solution is not secure. I will check other solution.

Remote samba and I will cut the forwarding later.
> sudo apt-get remove samba

2. FTP/SFTP Solution
SFTP
Create the new user
> sudo useradd kiko -m -G users

> sudo useradd kangping -m -G users

> sudo useradd xieqiuyuan -m -G users

> sudo passwd kiko

> sudo passwd kangping

> sudo passwd xieqiuyuan

Mapping the disk to the new user
> sudo ln -s /opt/disk1/share /home/sillycat/home-nas

Then we can use some other SFTP client to directly connect to server from SSH port.
FileZilla and other things. But it seems that we can not limit the user to its own directory.

FTP
http://mina.apache.org/ftpserver-project/

Download the latest version
> wget http://apache.mirrors.lucidnetworks.net/mina/ftpserver/1.0.6/dist/ftpserver-1.0.6.tar.gz

Unzip and place in the working directory
Command to run
> bin/ftpd.sh res/conf/ftpd-typical.xml

Prepare the directory
> sudo ln -s /opt/disk1/users/sillycat /opt/ftpserver/res/home/sillycat/sillycat

> sudo ln -s /opt/disk1/share /opt/ftpserver/res/home/sillycat/share

FTP Command Line
> sudo apt-get install ftp

> ftp localhost 2121

I login the system with these command
ftp localhost 2121
Connected to localhost.
220 Service ready for new user.
Name (localhost:carl): sillycat
331 User name okay, need password for sillycat.
Password:
230 User logged in, proceed.
Remote system type is UNIX.
ftp>

Upload the file
ftp> put README.md

local: README.md remote: README.md
200 Command PORT okay.
150 File status okay; about to open data connection.
226 Transfer complete.

List the file
ftp> ls -l
200 Command PORT okay.
150 File status okay; about to open data connection.
-rw-------   1 user group            0 Nov  5 22:52 111.txt
-rw-------   1 user group          147 Nov  5 22:54 README.md
226 Closing data connection.

delete the file
ftp> mdelete 111.txt
mdelete 111.txt? y
250 Requested file action okay, deleted /111.txt.

3. Passive and Active in FTP
My just use very simple configuration in the ftp server, but it seems that I have some problem  on connect to it. So I come back and search what are the details in FTP protocol.

There are 2 Types of Data Transfers - Active (PORT) and Passive(PASV)
The client problem can specify active mode by sending the “PORT” command to instruct that the server should connect back to a specified IP address and port number and then send the data.

A client program can choose passive mode by using the “PASV” command to ask that the server tell the client an IP address and port number that the client can connect to and receive the data.
http://www.ncftp.com/ncftpd/doc/misc/ftp_and_firewalls.html

Active FTP :
     command : client >1023 -> server 21
     data    : client >1023 <- server 20

Passive FTP :
     command : client >1023 -> server 21
     data    : client >1024 -> server >1023

Command passive will on/off the mode

I will change to use passive mode and I will also have the settings as follow:
<server xmlns="http://mina.apache.org/ftpserver/spring/v1"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
  http://mina.apache.org/ftpserver/spring/v1 http://mina.apache.org/ftpserver/ftpserver-1.0.xsd

  "
id="nasServer"
        max-logins="20"
        anon-enabled="false"
        max-login-failures="3"
        login-failure-delay="500">
<listeners>
<nio-listener name="default" port="2121" local-address="192.168.0.198">

    <ssl>

                <keystore file="./res/ftpserver.jks" password="password" />
                    </ssl>
                    <data-connection idle-timeout="60">
                      <active enabled="false" local-address="192.168.0.198" local-port="2020" ip-check="true" />
                      <passive ports="2023-2043" address="192.168.0.198" external-address="sillycat.ddns.net" />
          </data-connection>

</nio-listener>

</listeners>
<file-user-manager file="./res/conf/users.properties" encrypt-passwords="false"/>
</server>

We can also adjust the logging here
/opt/ftpserver/common/classes

cat log4j.properties

log4j.rootLogger=INFO, R
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=./res/log/ftpd.log
log4j.appender.R.MaxFileSize=10MB
log4j.appender.R.MaxBackupIndex=10
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=[%5p] %d [%X{userName}] [%X{remoteIp}] %m%n

And I am using FileZilla on MAC and FTPManager on iOS.

References:
Previous Blog
http://sillycat.iteye.com/blog/2254550

Mac OS to samba
http://users.wfu.edu/yipcw/atg/apple/smb/

Remaining Rsync work
http://www.howtogeek.com/139433/how-to-turn-a-raspberry-pi-into-a-low-power-network-storage-device/
http://www.makeuseof.com/tag/turn-your-raspberry-pi-into-a-nas-box/

SFTP and Clients
https://cyberduck.io/
https://filezilla-project.org/

FTP
http://sillycat.iteye.com/blog/562426
http://sillycat.iteye.com/blog/562428

http://sillycat.iteye.com/blog/563904

http://sillycat.iteye.com/blog/563906
http://sillycat.iteye.com/blog/563908
http://sillycat.iteye.com/blog/563909

你可能感兴趣的:(Build Home NAS(2)SmbClient SFTP FTP)