使用python實現(xiàn)http及ftp服務進行數(shù)據(jù)傳輸?shù)姆椒?/h1>
更新時間:2018年10月26日 15:47:28 作者:mazhen1991
今天小編就為大家分享一篇使用python實現(xiàn)http及ftp服務進行數(shù)據(jù)傳輸?shù)姆椒?,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
服務器之間的http數(shù)據(jù)傳輸
直接使用python內(nèi)置的http服務:
python -m SimpleHTTPServer 8000
此時,輸入指令的目錄就已經(jīng)開啟了http服務,8000為端口(如不指定,默認為8000),如果我們需要在其他機器下垃取該目錄下的文件,只需在目標機器運行:
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是我設定的端口號,user是用戶名,12345是我指定的密碼,此時,我們至需要運行腳本,就可以使用ftp工具,連接該ftp服務器,并上傳文件了。
如果我們不使用我們自己編寫的腳本,而是直接使用內(nèi)置的腳本:
python -m pyftpdlib -p 8888
此時,連接該ftp服務器,使用的是默認的用戶:anonymous,但是當我們上傳文件時,會發(fā)現(xiàn),沒有該用戶的上傳權限,所以,這里建議自己編寫運行腳本。
以上這篇使用python實現(xiàn)http及ftp服務進行數(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ù)傳輸)實例講解
- 在python環(huán)境下運用kafka對數(shù)據(jù)進行實時傳輸?shù)姆椒?/a>
- Python爬蟲抓取手機APP的傳輸數(shù)據(jù)
- python網(wǎng)絡編程之數(shù)據(jù)傳輸UDP實例分析
- python實現(xiàn)udp數(shù)據(jù)報傳輸?shù)姆椒?/a>
- Python數(shù)據(jù)傳輸黏包問題
相關文章
-
如何利用Python統(tǒng)計正數(shù)和負數(shù)的個數(shù)
Python檢查數(shù)據(jù)中的正/負數(shù)是一種常見的數(shù)據(jù)處理操作,可以通過編寫代碼來實現(xiàn),下面這篇文章主要給大家介紹了關于如何利用Python統(tǒng)計正數(shù)和負數(shù)的個數(shù)的相關資料,需要的朋友可以參考下 2024-05-05
最新評論
服務器之間的http數(shù)據(jù)傳輸
直接使用python內(nèi)置的http服務:
python -m SimpleHTTPServer 8000
此時,輸入指令的目錄就已經(jīng)開啟了http服務,8000為端口(如不指定,默認為8000),如果我們需要在其他機器下垃取該目錄下的文件,只需在目標機器運行:
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是我設定的端口號,user是用戶名,12345是我指定的密碼,此時,我們至需要運行腳本,就可以使用ftp工具,連接該ftp服務器,并上傳文件了。
如果我們不使用我們自己編寫的腳本,而是直接使用內(nèi)置的腳本:
python -m pyftpdlib -p 8888
此時,連接該ftp服務器,使用的是默認的用戶:anonymous,但是當我們上傳文件時,會發(fā)現(xiàn),沒有該用戶的上傳權限,所以,這里建議自己編寫運行腳本。
以上這篇使用python實現(xiàn)http及ftp服務進行數(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ù)傳輸)實例講解
- 在python環(huán)境下運用kafka對數(shù)據(jù)進行實時傳輸?shù)姆椒?/a>
- Python爬蟲抓取手機APP的傳輸數(shù)據(jù)
- python網(wǎng)絡編程之數(shù)據(jù)傳輸UDP實例分析
- python實現(xiàn)udp數(shù)據(jù)報傳輸?shù)姆椒?/a>
- Python數(shù)據(jù)傳輸黏包問題
相關文章
如何利用Python統(tǒng)計正數(shù)和負數(shù)的個數(shù)
Python檢查數(shù)據(jù)中的正/負數(shù)是一種常見的數(shù)據(jù)處理操作,可以通過編寫代碼來實現(xiàn),下面這篇文章主要給大家介紹了關于如何利用Python統(tǒng)計正數(shù)和負數(shù)的個數(shù)的相關資料,需要的朋友可以參考下2024-05-05

