Sponsored Content
Full Discussion: upload file using cgi
Special Forums IP Networking upload file using cgi Post 302446868 by vistastar on Friday 20th of August 2010 02:30:05 AM
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.
 

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
explain_mknod(3)					     Library Functions Manual						  explain_mknod(3)

NAME
explain_mknod - explain mknod(2) errors SYNOPSIS
#include <libexplain/mknod.h> const char *explain_mknod(const char *pathname, mode_t mode, dev_t dev); const char *explain_errno_mknod(int errnum, const char *pathname, mode_t mode, dev_t dev); void explain_message_mknod(char *message, int message_size, const char *pathname, mode_t mode, dev_t dev); void explain_message_errno_mknod(char *message, int message_size, int errnum, const char *pathname, mode_t mode, dev_t dev); DESCRIPTION
These functions may be used to obtain explanations for errors returned by the mknod(2) system call. explain_mknod const char *explain_mknod(const char *pathname, mode_t mode, dev_t dev); The explain_mknod function is used to obtain an explanation of an error returned by the mknod(2) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. pathname The original pathname, exactly as passed to the mknod(2) system call. mode The original mode, exactly as passed to the mknod(2) system call. dev The original dev, exactly as passed to the mknod(2) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. Example: This function is intended to be used in a fashion similar to the following example: if (mknod(pathname, mode, dev) < 0) { fprintf(stderr, "%s ", explain_mknod(pathname, mode, dev)); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_mknod_or_die(3) function. explain_errno_mknod const char *explain_errno_mknod(int errnum, const char *pathname, mode_t mode, dev_t dev); The explain_errno_mknod function is used to obtain an explanation of an error returned by the mknod(2) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. pathname The original pathname, exactly as passed to the mknod(2) system call. mode The original mode, exactly as passed to the mknod(2) system call. dev The original dev, exactly as passed to the mknod(2) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. Example: This function is intended to be used in a fashion similar to the following example: if (mknod(pathname, mode, dev) < 0) { int err = errno; fprintf(stderr, "%s ", explain_errno_mknod(err, pathname, mode, dev)); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_mknod_or_die(3) function. explain_message_mknod void explain_message_mknod(char *message, int message_size, const char *pathname, mode_t mode, dev_t dev); The explain_message_mknod function is used to obtain an explanation of an error returned by the mknod(2) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. pathname The original pathname, exactly as passed to the mknod(2) system call. mode The original mode, exactly as passed to the mknod(2) system call. dev The original dev, exactly as passed to the mknod(2) system call. Example: This function is intended to be used in a fashion similar to the following example: if (mknod(pathname, mode, dev) < 0) { char message[3000]; explain_message_mknod(message, sizeof(message), pathname, mode, dev); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_mknod_or_die(3) function. explain_message_errno_mknod void explain_message_errno_mknod(char *message, int message_size, int errnum, const char *pathname, mode_t mode, dev_t dev); The explain_message_errno_mknod function is used to obtain an explanation of an error returned by the mknod(2) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. pathname The original pathname, exactly as passed to the mknod(2) system call. mode The original mode, exactly as passed to the mknod(2) system call. dev The original dev, exactly as passed to the mknod(2) system call. Example: This function is intended to be used in a fashion similar to the following example: if (mknod(pathname, mode, dev) < 0) { int err = errno; char message[3000]; explain_message_errno_mknod(message, sizeof(message), err, pathname, mode, dev); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } The above code example is available pre-packaged as the explain_mknod_or_die(3) function. SEE ALSO
mknod(2) create a special or ordinary file explain_mknod_or_die(3) create a special or ordinary file and report errors COPYRIGHT
libexplain version 0.52 Copyright (C) 2009 Peter Miller explain_mknod(3)
All times are GMT -4. The time now is 05:48 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy