使用python實(shí)現(xiàn)http及ftp服務(wù)進(jìn)行數(shù)據(jù)傳輸?shù)姆椒?/h1>
更新時(shí)間:2018年10月26日 15:47:28 作者:mazhen1991
今天小編就為大家分享一篇使用python實(shí)現(xiàn)http及ftp服務(wù)進(jìn)行數(shù)據(jù)傳輸?shù)姆椒ǎ哂泻芎玫膮⒖純r(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧
服務(wù)器之間的http數(shù)據(jù)傳輸
直接使用python內(nèi)置的http服務(wù):
python -m SimpleHTTPServer 8000
此時(shí),輸入指令的目錄就已經(jīng)開(kāi)啟了http服務(wù),8000為端口(如不指定,默認(rèn)為8000),如果我們需要在其他機(jī)器下垃取該目錄下的文件,只需在目標(biāo)機(jī)器運(yùn)行:
wget ip:port/文件名
速度杠桿的。
開(kāi)啟ftp上傳文件
安裝ftp的python第三方組件
pip install pyftpdlib
編寫(xiě)啟動(dòng)腳本
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
import os
def main():
# Instantiate a dummy authorizer for managing 'virtual' users
authorizer = DummyAuthorizer()
# Define a new user having full r/w permissions and a read-only
# anonymous user
authorizer.add_user('user', '12345', '.', perm='elradfmwM')
authorizer.add_anonymous(os.getcwd())
# Instantiate FTP handler class
handler = FTPHandler
handler.authorizer = authorizer
# Define a customized banner (string returned when client connects)
handler.banner = "pyftpdlib based ftpd ready."
# Specify a masquerade address and the range of ports to use for
# passive connections. Decomment in case you're behind a NAT.
#handler.masquerade_address = '151.25.42.11'
#handler.passive_ports = range(60000, 65535)
# Instantiate FTP server class and listen on 0.0.0.0:2121
address = ('', 8888)
server = FTPServer(address, handler)
# set a limit for connections
server.max_cons = 256
server.max_cons_per_ip = 5
# start ftp server
server.serve_forever()
if __name__ == '__main__':
main()
其中8888是我設(shè)定的端口號(hào),user是用戶名,12345是我指定的密碼,此時(shí),我們至需要運(yùn)行腳本,就可以使用ftp工具,連接該ftp服務(wù)器,并上傳文件了。
如果我們不使用我們自己編寫(xiě)的腳本,而是直接使用內(nèi)置的腳本:
python -m pyftpdlib -p 8888
此時(shí),連接該ftp服務(wù)器,使用的是默認(rèn)的用戶:anonymous,但是當(dāng)我們上傳文件時(shí),會(huì)發(fā)現(xiàn),沒(méi)有該用戶的上傳權(quán)限,所以,這里建議自己編寫(xiě)運(yùn)行腳本。
以上這篇使用python實(shí)現(xiàn)http及ftp服務(wù)進(jìn)行數(shù)據(jù)傳輸?shù)姆椒ň褪切【幏窒斫o大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:- python使用socket高效傳輸視頻數(shù)據(jù)幀(連續(xù)發(fā)送圖片)
- python使用tcp傳輸圖片數(shù)據(jù)
- python 中Arduino串口傳輸數(shù)據(jù)到電腦并保存至excel表格
- 對(duì)python中基于tcp協(xié)議的通信(數(shù)據(jù)傳輸)實(shí)例講解
- 在python環(huán)境下運(yùn)用kafka對(duì)數(shù)據(jù)進(jìn)行實(shí)時(shí)傳輸?shù)姆椒?/a>
- Python爬蟲(chóng)抓取手機(jī)APP的傳輸數(shù)據(jù)
- python網(wǎng)絡(luò)編程之?dāng)?shù)據(jù)傳輸U(kuò)DP實(shí)例分析
- python實(shí)現(xiàn)udp數(shù)據(jù)報(bào)傳輸?shù)姆椒?/a>
- Python數(shù)據(jù)傳輸黏包問(wèn)題
相關(guān)文章
-
windows中python實(shí)現(xiàn)自動(dòng)化部署
本文主要介紹了windows中python實(shí)現(xiàn)自動(dòng)化部署,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧 2022-08-08
-
如何利用Python統(tǒng)計(jì)正數(shù)和負(fù)數(shù)的個(gè)數(shù)
Python檢查數(shù)據(jù)中的正/負(fù)數(shù)是一種常見(jiàn)的數(shù)據(jù)處理操作,可以通過(guò)編寫(xiě)代碼來(lái)實(shí)現(xiàn),下面這篇文章主要給大家介紹了關(guān)于如何利用Python統(tǒng)計(jì)正數(shù)和負(fù)數(shù)的個(gè)數(shù)的相關(guān)資料,需要的朋友可以參考下 2024-05-05
-
Python django框架 web端視頻加密的實(shí)例詳解
這篇文章主要介紹了Python django框架 web端視頻加密,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下 2020-11-11
-
Python實(shí)現(xiàn)時(shí)間序列可視化的方法
matplotlib庫(kù)是一個(gè)用于創(chuàng)建出版質(zhì)量圖表的桌面繪圖包(2D繪圖庫(kù)),是Python中最基本的可視化工具。這篇文章主要介紹了Python時(shí)間序列可視化實(shí)現(xiàn),需要的朋友可以參考下 2019-08-08
最新評(píng)論
服務(wù)器之間的http數(shù)據(jù)傳輸
直接使用python內(nèi)置的http服務(wù):
python -m SimpleHTTPServer 8000
此時(shí),輸入指令的目錄就已經(jīng)開(kāi)啟了http服務(wù),8000為端口(如不指定,默認(rèn)為8000),如果我們需要在其他機(jī)器下垃取該目錄下的文件,只需在目標(biāo)機(jī)器運(yùn)行:
wget ip:port/文件名
速度杠桿的。
開(kāi)啟ftp上傳文件
安裝ftp的python第三方組件
pip install pyftpdlib
編寫(xiě)啟動(dòng)腳本
from pyftpdlib.authorizers import DummyAuthorizer
from pyftpdlib.handlers import FTPHandler
from pyftpdlib.servers import FTPServer
import os
def main():
# Instantiate a dummy authorizer for managing 'virtual' users
authorizer = DummyAuthorizer()
# Define a new user having full r/w permissions and a read-only
# anonymous user
authorizer.add_user('user', '12345', '.', perm='elradfmwM')
authorizer.add_anonymous(os.getcwd())
# Instantiate FTP handler class
handler = FTPHandler
handler.authorizer = authorizer
# Define a customized banner (string returned when client connects)
handler.banner = "pyftpdlib based ftpd ready."
# Specify a masquerade address and the range of ports to use for
# passive connections. Decomment in case you're behind a NAT.
#handler.masquerade_address = '151.25.42.11'
#handler.passive_ports = range(60000, 65535)
# Instantiate FTP server class and listen on 0.0.0.0:2121
address = ('', 8888)
server = FTPServer(address, handler)
# set a limit for connections
server.max_cons = 256
server.max_cons_per_ip = 5
# start ftp server
server.serve_forever()
if __name__ == '__main__':
main()
其中8888是我設(shè)定的端口號(hào),user是用戶名,12345是我指定的密碼,此時(shí),我們至需要運(yùn)行腳本,就可以使用ftp工具,連接該ftp服務(wù)器,并上傳文件了。
如果我們不使用我們自己編寫(xiě)的腳本,而是直接使用內(nèi)置的腳本:
python -m pyftpdlib -p 8888
此時(shí),連接該ftp服務(wù)器,使用的是默認(rèn)的用戶:anonymous,但是當(dāng)我們上傳文件時(shí),會(huì)發(fā)現(xiàn),沒(méi)有該用戶的上傳權(quán)限,所以,這里建議自己編寫(xiě)運(yùn)行腳本。
以上這篇使用python實(shí)現(xiàn)http及ftp服務(wù)進(jìn)行數(shù)據(jù)傳輸?shù)姆椒ň褪切【幏窒斫o大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- python使用socket高效傳輸視頻數(shù)據(jù)幀(連續(xù)發(fā)送圖片)
- python使用tcp傳輸圖片數(shù)據(jù)
- python 中Arduino串口傳輸數(shù)據(jù)到電腦并保存至excel表格
- 對(duì)python中基于tcp協(xié)議的通信(數(shù)據(jù)傳輸)實(shí)例講解
- 在python環(huán)境下運(yùn)用kafka對(duì)數(shù)據(jù)進(jìn)行實(shí)時(shí)傳輸?shù)姆椒?/a>
- Python爬蟲(chóng)抓取手機(jī)APP的傳輸數(shù)據(jù)
- python網(wǎng)絡(luò)編程之?dāng)?shù)據(jù)傳輸U(kuò)DP實(shí)例分析
- python實(shí)現(xiàn)udp數(shù)據(jù)報(bào)傳輸?shù)姆椒?/a>
- Python數(shù)據(jù)傳輸黏包問(wèn)題
相關(guān)文章
windows中python實(shí)現(xiàn)自動(dòng)化部署
本文主要介紹了windows中python實(shí)現(xiàn)自動(dòng)化部署,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08
如何利用Python統(tǒng)計(jì)正數(shù)和負(fù)數(shù)的個(gè)數(shù)
Python檢查數(shù)據(jù)中的正/負(fù)數(shù)是一種常見(jiàn)的數(shù)據(jù)處理操作,可以通過(guò)編寫(xiě)代碼來(lái)實(shí)現(xiàn),下面這篇文章主要給大家介紹了關(guān)于如何利用Python統(tǒng)計(jì)正數(shù)和負(fù)數(shù)的個(gè)數(shù)的相關(guān)資料,需要的朋友可以參考下2024-05-05
Python django框架 web端視頻加密的實(shí)例詳解
這篇文章主要介紹了Python django框架 web端視頻加密,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-11-11
Python實(shí)現(xiàn)時(shí)間序列可視化的方法
matplotlib庫(kù)是一個(gè)用于創(chuàng)建出版質(zhì)量圖表的桌面繪圖包(2D繪圖庫(kù)),是Python中最基本的可視化工具。這篇文章主要介紹了Python時(shí)間序列可視化實(shí)現(xiàn),需要的朋友可以參考下2019-08-08

