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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Issues with extra characters at begininng of variable 2

Status
Not open for further replies.

MaxDes

IS-IT--Management
Aug 5, 2008
8
US
I am getting a weird x0cree added on to the file name of “name.ts”. I use scripts VERY similar to this one and they work fine, The only difference being the $localdir variable. I also tried chdir “s:\free”; as well with no luck…



This is my information:



This is my error:



[Mon Aug 04 16:13:31 2008] [error] [client 192.168.0.69] Cannot open Local file S:\x0creename.ts: No such file or directory, referer:
[Mon Aug 04 16:13:31 2008] [error] [client 192.168.0.69] at C:/CGI-bin/Encore.pl line 10, referer:


This is my script Encore.pl:


Code:
#!C:\Perl\bin\perl.exe

use CGI;':standard';

use Net::FTP;

my $q = new CGI;

my $thefile = $q->param('filename');

$localdir = "S:\free";

$ftpobj = Net::FTP -> new ("192.168.0.2");

$ftpobj -> login("guest","guest");

$ftpobj -> binary;

$ftpobj -> put ($localdir.$thefile);

$ftpobj -> quit;

unlink "$thefile";

print "Content-type: text/html\n\n";

print "\n<html><head>";

print "<title>Uploading Complete</title>";

print "</head>";

print "<body><h2>Uploading Complete</h2>";

print "</body></html>";


Please note that the s: drive is in fact a mapped network drive.



This is the html form that calls the script:


Code:
<form action="/cgi-bin/encore.pl" method="post"> Enter File Name: <input type="text" name="filename" /> <input type="submit" /> </form>



Any help would be great!



Thanks!



Marc Viste
 
Your are concatenting the localdir and filename together
$localdir.$thefile vs placing the file in the dir $localdir\$thefile.

Also, you should use

use strict
use CGI::Carp('fatalsToBrowser');
 
So I should have it read :

put ($localdir/$thefile)


?

backslash found where operator expected error now that I changed that....

Sorry I am kind of new to this whole perl thing.
 
Not sure about windows based dir structures, but try

put ($localdir\\$thefile) or

if $localdir is the defualt dir when u FTP in then;
put ($thefile) should work.
 
Well the point is I am trying to pull that file from a shared drive to the ftp location. so S:\free\$thefile is what I started with... no luck though.

That double slash errors out as well, but when I use the opposite slash it works, but again it adds the x0scree to the file name "name.ts" so it ends up as "x0screename.ts"

 
when $thefile gets passed, can u print that and see it's value, as from what u stated FTP is not the issue. Since u'r not doing $localdir.$thefile, nothing else is being added, unless it's being passed with that name...

or change POST to GET, to see the name in the URL.

my $thefile = $q->param('filename');
print $thefile;

Also, y r u del the file, if it's even being deleted?
unlink "$thefile";
 
\f in a double-quoted string is the meta character for a form feed:

Code:
$localdir = "S:\free";

change it to:

Code:
$localdir = 'S:\free';

also, you are doing something very insecure, passing a form input directly into a fuction with validating what the user has sent to your script.

Code:
my $thefile = $q->param('filename');

then later you have:

Code:
$ftpobj -> put ($localdir.$thefile);

Unless you trust everyone that uses the script to enter a trusted value for $thefile you should check that value before using it in the put() function.




------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
in my last post, this:

"into a fuction with validating"

should be:

"into a fuction without validating"




------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Ok when I do that I get :

useless use of constant i void context at line 2 cannot open local file s:\\freename.ts no such file or directory
 
post your latest code


------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Code:
#!C:\Perl\bin\perl.exe -w

use CGI;':standard';

use Net::FTP;

my $q = new CGI;

my $thefile = $q->param('filename');

$localdir = 'S:\free';

$ftpobj = Net::FTP -> new ("192.168.0.2");

$ftpobj -> login("guest","guest");

$ftpobj -> binary;

$ftpobj -> put ($localdir.$thefile);

$ftpobj -> quit;

unlink "$thefile";

print "Content-type: text/html\n\n";

print "\n<html><head>";

print "<title>Uploading Complete</title>";

print "</head>";

print "<body><h2>Uploading Complete</h2>";

print "</body></html>";
 
this line is wrong as the error indicates, the semi-colon after CGI:

Code:
use CGI;':standard';

should be:

Code:
use CGI;

since you are not using the :standard functions you should drop that.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
the script:
Code:
#!C:\Perl\bin\perl.exe -w
use CGI;
use Net::FTP;
my $q = new CGI;
#my $thefile = $q->param('filename');
$thefile = "name.ts";
my $dl = chr(92);
$localdir = join ($dl, "S:", "Free");
$filename = join ($dl, $localdir, $thefile);
$ftpobj = Net::FTP -> new ("200.20.34.119");
$ftpobj -> login("cms","cm5u53r");
$ftpobj -> binary;
$ftpobj -> put ($filename);
$ftpobj -> quit;
#unlink $filename;
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>";
the error:

[Tue Aug 05 10:47:08 2008] [error] [client 172.16.71.53] Cannot open Local file S:\\Free\\name.ts: No such file or directory, referer: [Tue Aug 05 10:47:08 2008] [error] [client 172.16.71.53] at C:/CGI-bin/Encore.pl line 13, referer:

Where are the double backslashes coming from? This is killing me!!!!
 
instead of this:

Code:
$thefile = "name.ts";
my $dl = chr(92);
$localdir = join ($dl, "S:", "Free");
$filename = join ($dl, $localdir, $thefile);

try:

Code:
$filename = 's:/free/name.ts';

Windows fully supports forward slashes in directory paths. Windows is also case insensitive so using all lower case should be no problem.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Ack dangit I left the correct line commented out! that line should be gone. The file name is a variable not a hard coded thing. So it should be :
Code:
my $thefile = $q->param('filename');
not
Code:
$thefile = "name.ts";
 
Code:
$filename = "s:/free/$thefile";

Using this code gives me the following error:

cannot open local file s:/Free/name.ts no such file or directory.

But there IS. So I either get the weird double slashes as so:

S:\\free\\name.ts

or the error above.

Man this makes no sense.... a bug in perl?

 
I guess the perl script can't get to the s:/ drive.

------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
Using mapped files is a COMPLETE pain.. always has been always will be. We get that question about 2-3 times a month. It just isn't dependable. I always map the drive, do the work, unmap the drive. It only seems to work well when running as administrator though.

Travis

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Can you use the \\server\path method rather than using a mapped drive?

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top