设为首页 收藏本站
查看: 682|回复: 0

[经验分享] Build Home NAS(2)SmbClient SFTP FTP

[复制链接]

尚未签到

发表于 2016-6-9 08:53:47 | 显示全部楼层 |阅读模式
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.iyunv.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.iyunv.com/blog/562426
http://sillycat.iyunv.com/blog/562428

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

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

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-228055-1-1.html 上篇帖子: ftp yum安装 tomcate jmx设置 下篇帖子: ftp 的几个常用命令 (链接)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表