Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ftplib library

Status
Not open for further replies.

behshad312

Programmer
May 13, 2008
2
0
0
IR
I can't upload very large files (more than 100 MB) on the site using ftplib library. Who shall help me?
 
Hi,
Thanks for your reply.
Python version: 2.4
code:
def uploadFile(user, client, post_data, appDir=""):
timeStamp = str( time.strftime( "%Y%m%d%H%M%S" ))
parentDir = str(client.clientId)
childDir = user.fullName.replace(' ','_') + '_' + timeStamp
uploadFile = post_data['filePath']

f = ftplib.FTP()
f.connect(settings.FTP_SERVER)
f.login(settings.FTP_USER,settings.FTP_PASSWORD)
f.cwd(WEB_ROOT_DIR)
try:
f.mkd(PROJECT_DATA_DIR)
except ftplib.error_perm:
pass
f.cwd(PROJECT_DATA_DIR)
try:
f.mkd(appDir)
except ftplib.error_perm:
pass
f.cwd(appDir)
try:
f.mkd(parentDir)
except ftplib.error_perm:
pass
f.cwd(parentDir)
f.mkd(childDir)
f.cwd(childDir)

fileName = uploadFile['filename'].replace(' ','_')
data = uploadFile['content']

os.chdir('/tmp')
temp = open(fileName,"wb")
temp.write(data)
temp.close()
size = os.path.getsize(fileName)
temp = open(fileName,"rb")
f.storbinary("STOR " + fileName,temp)
temp.close()
os.remove(fileName)
f.close()

return childDir, size

error message:
Timeout
The specified application exceeded the allowed time for processing. The server has deleted the process.

Please guid me.
 
Timeout
The specified application exceeded the allowed time for processing. The server has deleted the process.

seems to be a problem at the server side
I'm guessing you're on Windows
and I'm guessing if you try your upload using Microsoft's ftp.exe, that you'll get the same error.
If so (can you try that?), then the problem is not with python but with your FTP server or perhaps your network.

looking at your code further...I see you write to your temp file only to read it back in for storbinary
and you are doing that after you've connected to your server

try moving the 'writing to your temp file' before you even connect to your server

i.e., (pseudo)

write tempfile
connect to server
create dirs in server
storbinary

it might be that your timeout is being raised due to the time you spend writing to your temp file while your connection has already been established

i.e.,

Code:
    f.cwd(childDir)

# wasted time here with already open connection
fileName = uploadFile['filename'].replace(' ','_')
data = uploadFile['content']

os.chdir('/tmp')
temp = open(fileName,"wb")
temp.write(data)
temp.close()
size = os.path.getsize(fileName)
temp = open(fileName,"rb")

Code:
    f.storbinary("STOR " + fileName,temp)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top