FTP Client Speed via Scripting

Thank you for the suggestions. Using PGriffith’s suggestion I was able to use the java libraries and reduce the time to download a batch of files from 4.5 minutes to 11.5 seconds. For anyone use who is curious, here’s a chunk of what I came up with:

import os
from java.net import URL
from java.net import URLConnection
from java.io import BufferedReader
from java.io import InputStream
from java.io import InputStreamReader

def getInputStream(robotController, path):
	ftpUrl = "ftp://%s:%s@%s/%s" % (robotController[2], robotController[3], robotController[1], path)
	url = URL(ftpUrl)
	urlConnection = url.openConnection()
	inputStream = urlConnection.getInputStream()
	return inputStream

def downloadFile(robotController, fileName, folder):
	inputStream = getInputStream(robotController, fileName)
	
	streamReader = InputStreamReader(inputStream)
	reader = BufferedReader(streamReader)
	
	fileData = []
	line = reader.readLine()
	while line != None:
		fileData.append(line)
		line = reader.readLine()
	inputStream.close()
	
	saveFilePath = os.path.join(folder, fileName)
	try:
		file = open(saveFilePath, 'w')
		for line in fileData:
			file.write("%s\n" % (line))
		file.close()
	except Exception, ex:
		writeMessage("Error writing %s : %s" % (fileName, str(ex)))
4 Likes