upload file using cgi


 
Thread Tools Search this Thread
Special Forums IP Networking upload file using cgi
# 1  
Old 08-13-2010
upload file using cgi

I am using cgic lib to implement file upload, but the speed is very very slow... what is even worse, the file uploaded to my website is corrupted.

pakages captured by wireshark:
...

9606 56.258491 192.168.7.77 192.168.7.235 HTTP Continuation or non-HTTP traffic
9621 56.596617 192.168.7.77 192.168.7.235 HTTP [TCP Retransmission] Continuation or non-HTTP traffic
9604 56.258445 192.168.7.77 192.168.7.235 HTTP Continuation or non-HTTP traffic
9623 56.601372 192.168.7.77 192.168.7.235 HTTP Continuation or non-HTTP traffic
9624 56.601383 192.168.7.77 192.168.7.235 HTTP Continuation or non-HTTP traffic
...

Anyone has a good solution?
# 2  
Old 08-13-2010
That packet dump doesn't tell us anything. We need to see your code.
# 3  
Old 08-20-2010
Code:
int upfile(char *fpath,struct list *lpublic, struct list *lsystem)
{

    char *path_conf=(char *)malloc(1024);
    memset(path_conf,0,1024);

    sprintf(path_conf,"/mnt/%s",fpath);    

    cgiFilePtr file;
    char name[1024];
    int targetFile; 
    mode_t mode;

    char buffer[1024]; 
    int got; 
    if (cgiFormFileName("myFile", name, sizeof(name)) != cgiFormSuccess)  
    {
        free(path_conf);

        return -1; 
    }

    if (cgiFormFileOpen("myFile", &file) != cgiFormSuccess) 
    {
        fprintf(stderr, "Could not open the file.<p>\n");
        free(path_conf);

        return 0;
    }  

    mode=S_IRWXU|S_IRGRP|S_IROTH; 

targetFile=open(path_conf,O_RDWR|O_CREAT|O_TRUNC|O_APPEND,mode); 
    if(targetFile == -1)
    { 
        fprintf(stderr,"could not create the new file,%s\n",fpath); 
        free(path_conf);

        return 0; 
    } 

    while (cgiFormFileRead(file, buffer, 1024, &got)  ==cgiFormSuccess)
    { 
        if(got>0) 
        write(targetFile,buffer,got);  
    } 

    cgiFormFileClose(file); 
    close(targetFile);  

    free(path_conf);

    return 1;
}

this is the code.
When I upload a file larger than about 20M, the file uploaded to server corrupts. During transfer, it doesn't corrupt at starting , when a few minite latter the file (still transfering) suddenly corrupts at the date that already transfered to server, while the date latter transfered to the server doesn't corrupt.
# 4  
Old 08-26-2010
You should check the return value of write, sometimes it may not have written all the data you requested it to.
# 5  
Old 08-29-2010
Thanks for your reply

Last edited by Scott; 08-30-2010 at 02:37 AM..
# 6  
Old 10-07-2010
There are several ways to set up a script to do file upload for you. The simplest is described on the cgi-lib home page. To do it you simply write an HTML form that includes:

enctype="multipart/form-data"
An attribute of the <form> tag
<form enctype="multipart/form-data" action="...">
input type="file"
The tag that gets the file name and path
<input type="file" name="uploadfile" />
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

File upload message in SFTP

Hi, Below script is running on AIX 7.1 ( 7100-04-05-1720 version ) server. Recently OpenSSH version installed on server got updated from OpenSSH_6.0p1 to OpenSSH_7.5p1 version. After this update we do not receive any file upload message after put/mput command in SFTP. sftp -b - user@server... (1 Reply)
Discussion started by: Juggernaut
1 Replies

2. Shell Programming and Scripting

Upload latest file to ftp

Hi, I want to create a script that parses the content of a file (on each line there is a filename with full path containing the latest fiels created on that day) and uploads every file to a ftp location. Any elegant way to do it ? (4 Replies)
Discussion started by: liviusbr
4 Replies

3. Shell Programming and Scripting

Perl cgi pages out of cgi-bin folder in WINDOWS

Hi team, I have a typical problem with cgi pages in apache webserver in WINDOWS I am able to execute(display) the pages that are saved in cgi-bin folder. But I am not able to execute the pages stored in htdocs or other folder other than cgi-bin folder. Could anyone please let me know how... (1 Reply)
Discussion started by: scriptscript
1 Replies

4. Programming

File upload problems

When I upload image files they have the same extension twice. And my script doesn't show it even it the path is correct. Some scripts copy the file from the tmp dir server to the required directory, while others just move it. What happens to the files that were just copied? Do they stay... (1 Reply)
Discussion started by: AimyThomas
1 Replies

5. Ubuntu

how to upload comman file

Hi, How to upload multiple file using jsp on eclipse,give me a simple example for that. Thanks SN (0 Replies)
Discussion started by: snallusami
0 Replies

6. Shell Programming and Scripting

File upload through curl

hi; I need a script to upload a file using HTTP(curl post) to another system. Will appreciate ur help. Thnks; (0 Replies)
Discussion started by: ajaypadvi
0 Replies

7. Linux

restrict file download not upload

hi everybody, How cud i stop downloading files from FTP and allow uploading files in FTP. Thanks & reg, (2 Replies)
Discussion started by: utpalsarkar
2 Replies

8. Shell Programming and Scripting

stuck in perl cgi to upload a file to server

hi, i m working on a perl cgi script which uploads a file to the server. i m stuck. i hav written the errors. plz help. Sachin Kaw ______________________________________________________________________ #!/usr/bin/perl -w use CGI; use CGI qw(:standard); use strict; use POSIX... (4 Replies)
Discussion started by: sachin_kaw
4 Replies

9. UNIX for Advanced & Expert Users

Changing file permissions on upload

Hello ! When I connect to a RH FTP server, the files I transfer (from my "windows computer") to this server have the following permissions : -rw------- but I would like those files to have the following permissions : - rw-rw-r-x How can I do that ??? :) Thanks for your help ! G. (6 Replies)
Discussion started by: guix
6 Replies

10. Shell Programming and Scripting

CGI passing arrays/hashes to another CGI script

If I have a Perl CGI script (script01), which fills an array(s) with information and outputs a HTML page with a link to another CGI page (script02); is there anyway to pass the array(s) from "script01" to "script02" when the page visitor clicks the link? Hope that makes sense! :) (2 Replies)
Discussion started by: WIntellect
2 Replies
Login or Register to Ask a Question