本文实例讲述了python实现的简单FTP上传下载文件的方法。分享给大家供大家参考。具体如下:
python本身自带一个FTP模块,可以实现上传下载的函数功能。
#!/usr/bin/env python # -*- coding: utf-8 -*- from ftplib import FTP def ftp_up(filename = "20120904.rar"): ftp=FTP() ftp.set_debuglevel(2) #打开调试级别2,显示详细信息;0为关闭调试信息 ftp.connect('192.168.0.1','21') #连接 ftp.login('admin','admin') #登录,如果匿名登录则用空串代替即可 #print ftp.getwelcome() #显示ftp服务器欢迎信息 #ftp.cwd('xxx/xxx/') #选择操作目录 bufsize = 1024 #设置缓冲块大小 file_handler = open(filename,'rb') #以读模式在本地打开文件 ftp.storbinary('STOR %s' % os.path.basename(filename),file_handler,bufsize) #上传文件 ftp.set_debuglevel(0) file_handler.close() ftp.quit() print "ftp up OK" def ftp_down(filename = "20120904.rar"): ftp=FTP() ftp.set_debuglevel(2) ftp.connect('192.168.0.1','21') ftp.login('admin','admin') #print ftp.getwelcome() #显示ftp服务器欢迎信息 #ftp.cwd('xxx/xxx/') #选择操作目录 bufsize = 1024 filename = "20120904.rar" file_handler = open(filename,'wb').write #以写模式在本地打开文件 ftp.retrbinary('RETR %s' % os.path.basename(filename),file_handler,bufsize) #接收服务器上文件并写入本地文件 ftp.set_debuglevel(0) file_handler.close() ftp.quit() print "ftp down OK"
希望本文所述对大家的Python程序设计有所帮助。

SlicingaPythonlistisdoneusingthesyntaxlist[start:stop:step].Here'showitworks:1)Startistheindexofthefirstelementtoinclude.2)Stopistheindexofthefirstelementtoexclude.3)Stepistheincrementbetweenelements.It'susefulforextractingportionsoflistsandcanuseneg

numpyallowsforvariousoperationsonArrays:1)basicarithmeticlikeaddition,減法,乘法和division; 2)evationAperationssuchasmatrixmultiplication; 3)element-wiseOperations wiseOperationswithOutexpliitloops; 4)

Arresinpython,尤其是Throughnumpyandpandas,weessentialFordataAnalysis,offeringSpeedAndeffied.1)NumpyArseNable efflaysenable efficefliceHandlingAtaSetSetSetSetSetSetSetSetSetSetSetsetSetSetSetSetsopplexoperationslikemovingaverages.2)

列表sandnumpyArraysInpythonHavedIfferentMemoryfootprints:listSaremoreFlexibleButlessMemory-效率,而alenumpyArraySareSareOptimizedFornumericalData.1)listsStorReereReereReereReereFerenceStoObjects,with withOverHeadeBheadaroundAroundaround64byty64-bitsysysysysysysysysyssyssyssyssysssyssys2)

toensurepythonscriptsbehavecorrectlyacrycrosdevelvermations,分期和生產,USETHESTERTATE:1)Environment varriablesForsimplesettings,2)configurationfilesfilesForcomPlexSetups,3)dynamiCofforComplexSetups,dynamiqualloadingForaptaptibality.eachmethodoffersuniquebeneiquebeneqeniquebenefitsandrefitsandrequiresandrequiresandrequiresca

Python列表切片的基本語法是list[start:stop:step]。 1.start是包含的第一個元素索引,2.stop是排除的第一個元素索引,3.step決定元素之間的步長。切片不僅用於提取數據,還可以修改和反轉列表。

ListSoutPerformarRaysin:1)DynamicsizicsizingandFrequentInsertions/刪除,2)儲存的二聚體和3)MemoryFeliceFiceForceforseforsparsedata,butmayhaveslightperformancecostsinclentoperations。

toConvertapythonarraytoalist,usEthelist()constructororageneratorexpression.1)intimpthearraymoduleandcreateanArray.2)USELIST(ARR)或[XFORXINARR] to ConconverTittoalist,請考慮performorefformanceandmemoryfformanceandmemoryfformienceforlargedAtasetset。


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SublimeText3漢化版
中文版,非常好用

VSCode Windows 64位元 下載
微軟推出的免費、功能強大的一款IDE編輯器

Dreamweaver CS6
視覺化網頁開發工具

Dreamweaver Mac版
視覺化網頁開發工具

SublimeText3 Linux新版
SublimeText3 Linux最新版