使用python實(shí)現(xiàn)http及ftp服務(wù)進(jìn)行數(shù)據(jù)傳輸?shù)姆椒?/h1>
更新時間:2018年10月26日 15:47:28 作者:mazhen1991
今天小編就為大家分享一篇使用python實(shí)現(xiàn)http及ftp服務(wù)進(jìn)行數(shù)據(jù)傳輸?shù)姆椒?,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
服務(wù)器之間的http數(shù)據(jù)傳輸
直接使用python內(nèi)置的http服務(wù):
python -m SimpleHTTPServer 8000
此時,輸入指令的目錄就已經(jīng)開啟了http服務(wù),8000為端口(如不指定,默認(rèn)為8000),如果我們需要在其他機(jī)器下垃取該目錄下的文件,只需在目標(biāo)機(jī)器運(yùn)行:
wget ip:port/文件名
速度杠桿的。
開啟ftp上傳文件
安裝ftp的python第三方組件
pip install pyftpdlib
編寫啟動腳本
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è)定的端口號,user是用戶名,12345是我指定的密碼,此時,我們至需要運(yùn)行腳本,就可以使用ftp工具,連接該ftp服務(wù)器,并上傳文件了。
如果我們不使用我們自己編寫的腳本,而是直接使用內(nèi)置的腳本:
python -m pyftpdlib -p 8888
此時,連接該ftp服務(wù)器,使用的是默認(rèn)的用戶:anonymous,但是當(dāng)我們上傳文件時,會發(fā)現(xiàn),沒有該用戶的上傳權(quán)限,所以,這里建議自己編寫運(yùn)行腳本。
以上這篇使用python實(shí)現(xiàn)http及ftp服務(wù)進(jìn)行數(shù)據(jù)傳輸?shù)姆椒ň褪切【幏窒斫o大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:- python使用socket高效傳輸視頻數(shù)據(jù)幀(連續(xù)發(fā)送圖片)
- python使用tcp傳輸圖片數(shù)據(jù)
- python 中Arduino串口傳輸數(shù)據(jù)到電腦并保存至excel表格
- 對python中基于tcp協(xié)議的通信(數(shù)據(jù)傳輸)實(shí)例講解
- 在python環(huán)境下運(yùn)用kafka對數(shù)據(jù)進(jìn)行實(shí)時傳輸?shù)姆椒?/a>
- Python爬蟲抓取手機(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ù)傳輸黏包問題
相關(guān)文章
-
windows中python實(shí)現(xiàn)自動化部署
本文主要介紹了windows中python實(shí)現(xiàn)自動化部署,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧 2022-08-08
-
如何利用Python統(tǒng)計(jì)正數(shù)和負(fù)數(shù)的個數(shù)
Python檢查數(shù)據(jù)中的正/負(fù)數(shù)是一種常見的數(shù)據(jù)處理操作,可以通過編寫代碼來實(shí)現(xiàn),下面這篇文章主要給大家介紹了關(guān)于如何利用Python統(tǒng)計(jì)正數(shù)和負(fù)數(shù)的個數(shù)的相關(guān)資料,需要的朋友可以參考下 2024-05-05
-
Python django框架 web端視頻加密的實(shí)例詳解
這篇文章主要介紹了Python django框架 web端視頻加密,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下 2020-11-11
最新評論
服務(wù)器之間的http數(shù)據(jù)傳輸
直接使用python內(nèi)置的http服務(wù):
python -m SimpleHTTPServer 8000
此時,輸入指令的目錄就已經(jīng)開啟了http服務(wù),8000為端口(如不指定,默認(rèn)為8000),如果我們需要在其他機(jī)器下垃取該目錄下的文件,只需在目標(biāo)機(jī)器運(yùn)行:
wget ip:port/文件名
速度杠桿的。
開啟ftp上傳文件
安裝ftp的python第三方組件
pip install pyftpdlib
編寫啟動腳本
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è)定的端口號,user是用戶名,12345是我指定的密碼,此時,我們至需要運(yùn)行腳本,就可以使用ftp工具,連接該ftp服務(wù)器,并上傳文件了。
如果我們不使用我們自己編寫的腳本,而是直接使用內(nèi)置的腳本:
python -m pyftpdlib -p 8888
此時,連接該ftp服務(wù)器,使用的是默認(rèn)的用戶:anonymous,但是當(dāng)我們上傳文件時,會發(fā)現(xiàn),沒有該用戶的上傳權(quán)限,所以,這里建議自己編寫運(yùn)行腳本。
以上這篇使用python實(shí)現(xiàn)http及ftp服務(wù)進(jìn)行數(shù)據(jù)傳輸?shù)姆椒ň褪切【幏窒斫o大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
- python使用socket高效傳輸視頻數(shù)據(jù)幀(連續(xù)發(fā)送圖片)
- python使用tcp傳輸圖片數(shù)據(jù)
- python 中Arduino串口傳輸數(shù)據(jù)到電腦并保存至excel表格
- 對python中基于tcp協(xié)議的通信(數(shù)據(jù)傳輸)實(shí)例講解
- 在python環(huán)境下運(yùn)用kafka對數(shù)據(jù)進(jìn)行實(shí)時傳輸?shù)姆椒?/a>
- Python爬蟲抓取手機(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ù)傳輸黏包問題
相關(guān)文章
windows中python實(shí)現(xiàn)自動化部署
本文主要介紹了windows中python實(shí)現(xiàn)自動化部署,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08
如何利用Python統(tǒng)計(jì)正數(shù)和負(fù)數(shù)的個數(shù)
Python檢查數(shù)據(jù)中的正/負(fù)數(shù)是一種常見的數(shù)據(jù)處理操作,可以通過編寫代碼來實(shí)現(xiàn),下面這篇文章主要給大家介紹了關(guān)于如何利用Python統(tǒng)計(jì)正數(shù)和負(fù)數(shù)的個數(shù)的相關(guān)資料,需要的朋友可以參考下2024-05-05
Python django框架 web端視頻加密的實(shí)例詳解
這篇文章主要介紹了Python django框架 web端視頻加密,本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-11-11

