服務(wù)器之間的http數(shù)據(jù)傳輸
直接使用python內(nèi)置的http服務(wù):
python -m SimpleHTTPServer 8000
此時,輸入指令的目錄就已經(jīng)開啟了http服務(wù),8000為端口(如不指定,默認(rèn)為8000),如果我們需要在其他機器下垃取該目錄下的文件,只需在目標(biāo)機器運行:
wget ip:port/文件名
速度杠桿的。
開啟ftp上傳文件
安裝ftp的python第三方組件
pip install pyftpdlib
編寫啟動腳本
from pyftpdlib.authorizers import DummyAuthorizerfrom pyftpdlib.handlers import FTPHandlerfrom pyftpdlib.servers import FTPServerimport osdef 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是我指定的密碼,此時,我們至需要運行腳本,就可以使用ftp工具,連接該ftp服務(wù)器,并上傳文件了。
如果我們不使用我們自己編寫的腳本,而是直接使用內(nèi)置的腳本:
python -m pyftpdlib -p 8888
此時,連接該ftp服務(wù)器,使用的是默認(rèn)的用戶:anonymous,但是當(dāng)我們上傳文件時,會發(fā)現(xiàn),沒有該用戶的上傳權(quán)限,所以,這里建議自己編寫運行腳本。
以上這篇使用python實現(xiàn)http及ftp服務(wù)進行數(shù)據(jù)傳輸?shù)姆椒ň褪切【幏窒斫o大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持VEVB武林網(wǎng)。
新聞熱點
疑難解答
圖片精選