在內網架設一個可供外網登陸的ftp服務器

ftp服務器是使用比較日常的服務器,可是IP資源是有限的,那麼怎麼讓內網的服務器給外網的用戶提供服務了?mysql

首先須要找一個FTP服務器程序,我在這邊使用pure-ftpd-mysql ,這邊使用-mysql版本是爲了方便用戶管理,同時經過數據庫能夠很好的和其中應用結合起來.sql

安裝pure-ftpd-mysql數據庫

我使用的是ubuntu,因此安裝沒有從源碼編譯,直接 sudo apt-get install pure-ftpd-mysql .而後使用sudo service pure-ftpd-mysql start開啓ftp服務器,這是它會打印一些啓動時的配置參數.想看參數能夠使用--h命令,能夠使用pure-ftpd-mysql -h > help保存到文件,而後看文件.ubuntu

參數:瀏覽器

-0    --notruncate    
-1    --logpid    
-4    --ipv4only    
-6    --ipv6only    
-8    --fscharset    <opt>
-9    --clientcharset    <opt>
-A    --chrooteveryone    
-a    --trustedgid    <opt>
-b    --brokenclientscompatibility    
-B    --daemonize    
-C    --maxclientsperip    <opt>
-c    --maxclientsnumber    <opt>
-d    --verboselog    
-D    --displaydotfiles    
-e    --anonymousonly    
-E    --noanonymous    
-f    --syslogfacility    <opt>
-F    --fortunesfile    <opt>
-g    --pidfile    <opt>
-G    --norename    
-h    --help    
-H    --dontresolve    
-I    --maxidletime    <opt>
-i    --anonymouscantupload    
-j    --createhomedir    
-K    --keepallfiles    
-k    --maxdiskusagepct    <opt>
-l    --login    <opt>
-L    --limitrecursion    <opt>
-M    --anonymouscancreatedirs    
-m    --maxload    <opt>
-N    --natmode    
-n    --quota    <opt>
-o    --uploadscript    
-O    --altlog    <opt>
-p    --passiveportrange    <opt>
-P    --forcepassiveip    <opt>
-q    --anonymousratio    <opt>
-Q    --userratio    <opt>
-r    --autorename    
-R    --nochmod    
-s    --antiwarez    
-S    --bind    <opt>
-t    --anonymousbandwidth    <opt>
-T    --userbandwidth    <opt>
-U    --umask    <opt>
-u    --minuid    <opt>
-V    --trustedip    <opt>
-w    --allowuserfxp    
-W    --allowanonymousfxp    
-x    --prohibitdotfileswrite    
-X    --prohibitdotfilesread    
-y    --peruserlimits    <opt>
-Y    --tls    <opt>
-J    --tlsciphersuite    <opt>
-z    --allowdotfiles    
-Z    --customerproof   
下面怎麼控制用戶訪問,到/etc/pure-ftpd/db下,而後配置mysql.conf文件,mysql的IP,Port,user,password,database,而後是進行驗證的sql語句,個人表是我users,其中有三個字段,用戶名,密碼,用戶登陸後的目錄,UID和GID默認的是1000.
服務器


如今你在瀏覽器中,輸入ftp://127.0.0.1,輸入數據庫中的保存的數據就能夠登陸了.ui

下面對ftp配置,配置文件在/etc/pure-ftpd/conf,其一個配置項爲一個文件,默認有AltLog     MinUID           NoAnonymous        PureDB
FSCharset  MySQLConfigFile  PAMAuthentication  UnixAuthentication

其實文件名就是-h命令打印的參數全名.好比-p參數--passiveportrange,先建一個PassivePortRange文件,注意文件名,小寫不認的.
spa

內容爲45000 50000,標識被動模式的端口範圍,在不須要客戶端有任何變化狀況下訪問內網的ftp,使用被動是最好的,有興趣能夠看看主動和被動的區別.ip

從新啓動ftpci

能夠看到-p參數有效果了.那麼怎麼讓外網訪問,須要將21端口和45000~50000端口映射到路由器上的端口,ip爲你內網的地址.進入路由器,轉發規則,虛擬服務器

如今使用外網登陸

ok,搞定收工

相關文章
相關標籤/搜索