How to serve file from different computer with cgi script

How to serve file from different computer with cgi script

Post by dave fournie » Thu, 12 Oct 2000 09:01:03



Hi,

I would like to be able to serve a file from a different computer.
I have written a cgi script which uses ftp to get the file and writes it
into a
fifo the fifo is then written to standard output. sometimes it works.
However extra characte or missing characters show up. Any ideas how to
fix this
up or a better way to do it would be appreciated.

this is my cgi script. the fifo was made with the command

   mknod tmpipe1 p

#!/bin/bash
#
echo Content-type: application/octet_stream  
echo Content-length: 1746764  
echo  
ncftpget -u ftp  -A xx.xx.xx.xx  /cgi-bin tmppipe1 &
cat < /tmppipe1  

    thanks,

     Dave

--
David A Fournier  PO Box 2040
Sidney, B.C. V8L 3S3 Canada
Phone: 250-655-3364

--
David A Fournier  PO Box 2040
Sidney, B.C. V8L 3S3 Canada
Phone: 250-655-3364

 
 
 

How to serve file from different computer with cgi script

Post by Barry Margoli » Thu, 12 Oct 2000 04:00:00




Quote:>Hi,

>I would like to be able to serve a file from a different computer.
>I have written a cgi script which uses ftp to get the file and writes it
>into a
>fifo the fifo is then written to standard output. sometimes it works.
>However extra characte or missing characters show up. Any ideas how to
>fix this
>up or a better way to do it would be appreciated.

When you run a command in the background, the shell prints the PID, and
that's probably the extra characters you see.  And the missing characters
are probably at the end, because the Content-Length you send doesn't count
those extra characters at the beginning.

Change it to:

(ncftpget ... &)

and the "[1] PID" message should go away.

>this is my cgi script. the fifo was made with the command

>   mknod tmpipe1 p

>#!/bin/bash
>#
>echo Content-type: application/octet_stream  
>echo Content-length: 1746764  
>echo  
>ncftpget -u ftp  -A xx.xx.xx.xx  /cgi-bin tmppipe1 &
>cat < /tmppipe1  

>    thanks,

>     Dave

>--
>David A Fournier  PO Box 2040
>Sidney, B.C. V8L 3S3 Canada
>Phone: 250-655-3364

>--
>David A Fournier  PO Box 2040
>Sidney, B.C. V8L 3S3 Canada
>Phone: 250-655-3364


--

Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

How to serve file from different computer with cgi script

Post by dave fournie » Thu, 12 Oct 2000 04:00:00


Thanks for the advice. I was able to find the source code for
ncftpget and modify the code to print to stdout. That way I didn't need
the named pipe or cat and the problem seems to have gone away.

     Dave



> >Hi,

> >I would like to be able to serve a file from a different computer.
> >I have written a cgi script which uses ftp to get the file and writes it
> >into a
> >fifo the fifo is then written to standard output. sometimes it works.
> >However extra characte or missing characters show up. Any ideas how to
> >fix this
> >up or a better way to do it would be appreciated.

> When you run a command in the background, the shell prints the PID, and
> that's probably the extra characters you see.  And the missing characters
> are probably at the end, because the Content-Length you send doesn't count
> those extra characters at the beginning.

> Change it to:

> (ncftpget ... &)

> and the "[1] PID" message should go away.

> >this is my cgi script. the fifo was made with the command

> >   mknod tmpipe1 p

> >#!/bin/bash
> >#
> >echo Content-type: application/octet_stream
> >echo Content-length: 1746764
> >echo
> >ncftpget -u ftp  -A xx.xx.xx.xx  /cgi-bin tmppipe1 &
> >cat < /tmppipe1

> >    thanks,

> >     Dave

> >--
> >David A Fournier  PO Box 2040
> >Sidney, B.C. V8L 3S3 Canada
> >Phone: 250-655-3364

> >--
> >David A Fournier  PO Box 2040
> >Sidney, B.C. V8L 3S3 Canada
> >Phone: 250-655-3364

> --

> Genuity, Burlington, MA
> *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
> Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

--
David A Fournier  PO Box 2040
Sidney, B.C. V8L 3S3 Canada
Phone: 250-655-3364

 
 
 

How to serve file from different computer with cgi script

Post by Barry Margoli » Thu, 12 Oct 2000 04:00:00





>Thanks for the advice. I was able to find the source code for
>ncftpget and modify the code to print to stdout. That way I didn't need
>the named pipe or cat and the problem seems to have gone away.

If your OS has /dev/stdout, you don't need to modify ncftpget.

--

Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

 
 
 

How to serve file from different computer with cgi script

Post by dave fournie » Thu, 12 Oct 2000 04:00:00


Well it's done now but for future problems could you elaborate.




> >Thanks for the advice. I was able to find the source code for
> >ncftpget and modify the code to print to stdout. That way I didn't need
> >the named pipe or cat and the problem seems to have gone away.

> If your OS has /dev/stdout, you don't need to modify ncftpget.

> --

> Genuity, Burlington, MA
> *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
> Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

--
David A Fournier  PO Box 2040
Sidney, B.C. V8L 3S3 Canada
Phone: 250-655-3364

 
 
 

How to serve file from different computer with cgi script

Post by Barry Margoli » Thu, 12 Oct 2000 04:00:00





>Well it's done now but for future problems could you elaborate.

If you write to the special file /dev/stdout, it goes to standard output.
This is how you can get any program that takes a filename as a parameter
and trick it into writing to stdout (unless the program really requires
that the filename point to an ordinary file -- but such a program wouldn't
work with a named pipe, either).  There are also special files /dev/stdin
and /dev/stderr, that correspond to those standard descriptors.




>> >Thanks for the advice. I was able to find the source code for
>> >ncftpget and modify the code to print to stdout. That way I didn't need
>> >the named pipe or cat and the problem seems to have gone away.

>> If your OS has /dev/stdout, you don't need to modify ncftpget.

>> --

>> Genuity, Burlington, MA
>> *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
>> Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

>--
>David A Fournier  PO Box 2040
>Sidney, B.C. V8L 3S3 Canada
>Phone: 250-655-3364


--

Genuity, Burlington, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
 
 
 

How to serve file from different computer with cgi script

Post by dave fournie » Thu, 12 Oct 2000 04:00:00


Yes but the program doesn't let you specify name of the output
file as far as I could see.
It uses the same name as the file you are fetching. That's why
I had to change the source. Perhaps one could make a symbolic link
to /dev/sdout ?  as

   ln -s tmpfile /dev/sdout




> >Well it's done now but for future problems could you elaborate.

> If you write to the special file /dev/stdout, it goes to standard output.
> This is how you can get any program that takes a filename as a parameter
> and trick it into writing to stdout (unless the program really requires
> that the filename point to an ordinary file -- but such a program wouldn't
> work with a named pipe, either).  There are also special files /dev/stdin
> and /dev/stderr, that correspond to those standard descriptors.




> >> >Thanks for the advice. I was able to find the source code for
> >> >ncftpget and modify the code to print to stdout. That way I didn't need
> >> >the named pipe or cat and the problem seems to have gone away.

> >> If your OS has /dev/stdout, you don't need to modify ncftpget.

> >> --

> >> Genuity, Burlington, MA
> >> *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
> >> Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

> >--
> >David A Fournier  PO Box 2040
> >Sidney, B.C. V8L 3S3 Canada
> >Phone: 250-655-3364

> --

> Genuity, Burlington, MA
> *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
> Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.

--
David A Fournier  PO Box 2040
Sidney, B.C. V8L 3S3 Canada
Phone: 250-655-3364

 
 
 

1. does a cgi script only serve the cgi or images as well?

Assuming the CGI script is just writing HTML code that includes <IMG> tags,
then either the browser has them cached (as you suspected) or the web server
is set not to log images.

The way to test the browser thing would be a forced reload. In Netscape, you
can do this with Shift-Reload of the page. For IE, the only way I know of is
to quit the program and then purge the cache.


** Remove the REMOVE in my address address to reply reply  **

2. Samba Problem

3. serving cgi scripts as index files

4. HELP! My X windows fonts are disappearing on me!!

5. serving cgi files and html files in same directory

6. ipf and gen'l network woes?

7. Proxy serving CGI scripts via Apache...

8. AIX 4.2.3/MF Cobol 4.1/EOL Key

9. Writing CGI Scripts in C and Serving with Apache

10. Serving different file types in Apache 1.2?

11. How to serve index.cgi from cgi directory

12. Setting the filename for files being served via cgi

13. How do I get a cgi to serve files from a superuser directory?