MaxDes has asked for the wisdom of the Perl Monks concerning the following question:

#!C:\Perl\bin\perl.exe -w use CGI; use Net::FTP; my $q = new CGI; my $thefile = $q->param('filename'); $dir = 'S:/Free'; $ftpobj = Net::FTP -> new ("192.168.0.2"); $ftpobj -> login("cms","cm5u53r"); $ftpobj -> binary; $ftpobj -> put ("$dir\\$thefile"); $ftpobj -> quit; print "Content-type: text/html\n\n"; print "\n<html><head>"; print "<title>Uploading Complete</title>"; print "</head>"; print "<body><h2>Uploading Complete</h2><br><br>filename: [$filename] +thefile: [$thefile]<br><br>"; print "</body></html>";
this script, although it looks correct in syntax gives me a weird result. When running the script from command line the directory passes correctly, but when running it with a web browser through cgi I get the following: Cannot open local file S:\\Free\\name.ts: no such file or directory. I've tried simpler versions of the same code with chdir and such, but I get the same result... Can anyone help?

Replies are listed 'Best First'.
Re: Bug in perl?
by kyle (Abbot) on Aug 05, 2008 at 20:11 UTC

    This syntax is valid, but I don't think it does what you want to do:

    $ftpobj -> put ($dir/$thefile);

    (Try "$thefile = '0'" for some infinite fun.)

    I think you mean:

    $ftpobj->put( "$dir/$thefile" );

    I'm not sure that's really the problem you're describing, however. Is this really the code you're using?

      Changed for your pleasure. the ACTUAL code since I buggered it a little bit retyping it all. no cut and paste for me since it's diff pcs. bah. The user/pw is no issue. It's all fake.
Re: Bug in perl?
by tilly (Archbishop) on Aug 05, 2008 at 20:08 UTC
    To repeat advice from the CB, you shouldn't post your login information publicly. Even though the machine is not publicly available, it is still a good practice to not put passwords out there.

    I would suggest that you use strict.pm. warnings is good as well.

    Also is it possible that you, for instance, have a space in the browser URL, resulting in a filename of 'name.ts ' (note the space) which does not exist? Try echoing the filename with quotes around it so you can see any such spaces. After a couple of nasty debugging sessions I do that as a matter of habit now.

    You have to look for things like that since the code itself is basically correct - the fact that you can run it from the command line proves that. So now you're looking for a PEBKAC problem. (Problem Exists Between the Keyboard And the Chair.)

Re: Bug in perl?
by eosbuddy (Scribe) on Aug 06, 2008 at 04:53 UTC
    Don't know if you've solved your problem. Also, I am surprised that windows would accept system administrator at FTP login (unix systems won't accept, by default, root logins - tweaking the config files it is possible to get this changed but highly discouraged as FTP is not a secure protocol). Given this situation... as I had seen in another post related to FTP put, one of the responders had suggested passive ftp (this node: http://perlmonks.org/?node_id=698377) - don't know whether it might work in your case :-)
Re: Bug in perl?
by chakram88 (Pilgrim) on Aug 05, 2008 at 19:59 UTC
    Just a guess --- is it permissions on the directory S:/Free?

    Your web server processes should be running as a user with limited privs.

      I am using an admin user and I have total access to that server's share.... I don't know why it's giving me the double slash thing... it's driving me nuts.