ftp - python ftplib hangs on upload (STOR) --- and not network latency -


i have simple utility script using ftplib on python 2.7 upload web files remote host. however, storlines hangs , sits there couple of minutes. doesn't have decency throw kind of exception.

  • i've verified connection works repl. storlines hangs both repl , commandline script.

  • my test file 22 bytes (not kb, bytes), seems unlikely things timing out. also, @ repl, after kill hung upload via cntrl-c, can output ftp.dir(), know i'm not losing connection @ point.

  • the aforementioned output ftp.dir() larger test file, , arrives within few seconds, know problem isn't network latency.

  • based on this prior so i've tried adding ftp.set_pasv(false) before upload function definition, nada.

does else have ideas going wrong here? here's code:

import sys ftplib import ftp ftp = ftp([myserver], [myuser], [mypassword]) full = sys.argv[1] path = 'public_html/' + full[:full.rfind('/') + 1] filename = full[full.rfind('/') + 1:] ftp.cwd(path)  def upload(method, mode, filename):     open(filename, mode) fileobject:         method('stor' +filename, fileobject)  if filename.endswith(('.htm','.html','.py','.cgi','.js','.css','.txt','.md', '.svg')):     upload(ftp.storlines, 'r', filename) else:     upload(ftp.storbinary, 'rb', filename) ftp.quit() print 'done!' 

and, seriously, full file i'm trying upload, filename test.md:

this test.  #test 

so ugly, figured out hack-tastic solution, lets nice existing ftp application written knows networking work:

import sys import os full = sys.argv[1] path = 'public_html/' + full[:full.rfind('/') + 1] filename = full[full.rfind('/') + 1:]  def picktype(filename):     if filename.endswith(('.htm','.html','.py','.cgi','.js','.css','.txt','.md', '.svg')):         return 'ascii'     return 'binary'  ftpstring = """ open [server] user [user] [password] cd {0} {1} put {2} bye """.format(path, picktype(filename), filename)  print ftpstring  open("tempfile.txt", 'w') tempfile:     tempfile.write(ftpstring)  os.system('ftp -n < tempfile.txt')  print 'done!' 

i know these days you're supposed use subprocess module kind of junk, can't life of me figure out how make redirection work.


Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -