Is Python FTPLib Too Slow?

I played with the Python FTP library and am starting to think that it is too slow compared to using a script file in DOS? I run sessions where I upload thousands of data files (I think I now have over 8 million). My observation is that the boot process seems to take five to ten times longer in Python than when compared to using ftp commands in the DOS shell.

Since I do not want anyone to correct my code, I did not enable it. I'm more interested in understanding whether my observation is really valid or if I need to go over the arguments more.

+3
source share
7 answers

FTPLib Python, "DOS Script" script, . , , , Python. , DOS Python subprocess module.

+2

FTPlib API Python, , , , DOS script.

- , , shell python dl 5000 , , .

+2

, . FTPlib 10 .

+2

define blockize storbinary ftp, 1.5-3.0x , FTP Filezilla:)

from ftplib import FTP

USER = "Your_user_id"
PASS = "Your_password"
PORT = 21
SERVER = 'ftp.billionuploads.com' #use FTP server name here

ftp = FTP()
ftp.connect(SERVER, PORT)
ftp.login(USER, PASS)

try:
    file = open(r'C:\Python27\1.jpg','rb')
    ftp.storbinary('STOR ' + '1.jpg', file,102400) #here we store file in 100kb blocksize
    ftp.quit()
    file.close()
    print "File transfered"
except:
    print "Error in File transfering"
+2
import ftplib
import time
ftp = ftplib.FTP("localhost", "mph")
t0 = time.time()
with open('big.gz.sav', 'wb') as f:
    ftp.retrbinary('RETR ' + '/Temp/big.gz', f.write)
t1 = time.time()
ftp.close()
ftp = ftplib.FTP("localhost", "mph")
t2 = time.time()
ftp.retrbinary('RETR ' + '/Temp/big.gz', lambda x: x)
t3 = time.time()
print "saving file: %f to %f: %f delta" % (t0, t1, t1 - t0)
print "not saving file: %f to %f: %f delta" % (t2, t3, t3 - t2)

, , 10x. 160 Core i7 1,8 8 ( overkill) Windows 7. 100 . 70-.

, ftplib mac ( , ). , , .

+1

ftplib ftp Msdos

os.system('FTP -v -i -s:C:\\ndfd\\wgrib2\\ftpscript.txt')

ftpscript.txt

open example.com
username
password
!:--- FTP commands below here ---
lcd c:\MyLocalDirectory
cd  public_html/MyRemoteDirectory
binary
mput "*.*"
disconnect
bye
+1

. , 167 FTP-, :

Blocksize  Time
102400       40
 51200       30
 25600       28
 32768       30
 24576       31
 19200       34
 16384       61
 12800      144

32768 (4x8192).

, :

Blocksize  Time
204800       78
102400       76
 51200       79
 25600       76
 32768       89
 24576       86
 19200       75
 16384      166
 12800      178
default     223

, 32768.

+1

Source: https://habr.com/ru/post/1707862/


All Articles