file name and FTP problem formatting date! Please Help!

N

Nex_s

Hi All,

I'm trying to format a date and store it in a variable for a file
name. The file gets created but for some reason my FTP process sends
an empty file with the same name.

Any help would be greatly appreciated.
Chris

Here's how I'm formatting the date.

$file = "dms_nspwr_" . `date +%b_%d_%y_%H%M.txt`;

Here's my FTP code:

$ftp = Net::FTP->new("123.456.789.10", Debug => 0)
or die "Cannot connect to some.host.name: $@";

$ftp->login("username",'password')
or die "Cannot login ", $ftp->message;

#$ftp->cwd("/pub")
# or die "Cannot change working directory ", $ftp->message;


$ftp->put("$file")
or die "put failed $file", $ftp->message;

$ftp->quit;
 
P

Paul Lalli

Nex_s said:
I'm trying to format a date and store it in a variable for a file
name. The file gets created but for some reason my FTP process sends
an empty file with the same name.

Any help would be greatly appreciated.
Here's how I'm formatting the date.

$file = "dms_nspwr_" . `date +%b_%d_%y_%H%M.txt`;

There's little need to shell this out to an external command. Check
out the strftime() function in
perldoc POSIX
Here's my FTP code:

$ftp = Net::FTP->new("123.456.789.10", Debug => 0)

You appear to not be using strict. Please make sure all your scripts
that you ask for help with here start with
use strict;
use warnings;

Also, as you seem to be having problems with the FTP class, perhaps it
would be a good idea to enable debugging, to ensure that your program
is doing what you think it's doing? Try replacing the end of that
constructor with:
Debug => 1)
or die "Cannot connect to some.host.name: $@";

$ftp->login("username",'password')
or die "Cannot login ", $ftp->message;

#$ftp->cwd("/pub")
# or die "Cannot change working directory ", $ftp->message;


$ftp->put("$file")

This is a useless use of double quotes, and is a bad habbit to get
into. Please read:
perldoc -q quoting
or die "put failed $file", $ftp->message;

$ftp->quit;

Have you verified that the file exists in the current local directory?
Have you verified that the file has content in the current local
directory?

Try adding these two lines before the $ftp->put():

-e $file or die "File $file does not exist!\n"
-s _ or die "File $file is empty!\n";

and let us know the results of those lines plus the Debugging output...

Paul Lalli
 
N

Nex_s

Hi there,

Thank you kindly for your response. I ran the code again the ftp
process ran flawlessly until the put statement when the error came
back:

File dms_nspwr_2005_08_02_1404.txt does not exist!

The file is in the same directory as the script and contains data. I
even tried putting in sleep 10 in case it was necessary to give the
server time to save the file but to no avail.

Chris

P.S. I tired explictly defining all my variables but ran into one
problem with one used for my e-mail routine $mail. The line in
question is:
$mail{From} = 'Data Upload <[email protected]>';
Here's the error it gave me.

Global symbol "%mail" requires explicit package name at line 147.
 
P

Paul Lalli

Paul said:
Hi there,

Thank you kindly for your response.

You're welcome. I would ask that you please show your gratitude by
following proper quoting guidelines - quote a *relevant* amount of text
*above* your new message. Thank you.
I ran the code again the ftp
process ran flawlessly until the put statement when the error came
back:

File dms_nspwr_2005_08_02_1404.txt does not exist!

The file is in the same directory as the script and contains data.

I'm afraid you're mistaken. That error message is very specifically
telling you that the file in question (is that the name you were
expecting for your file?) does not exist. Is your script doing any
chdir()'s along the way which may be changing the working directory?

What OS are you using, and how are you executing the script?
I
even tried putting in sleep 10 in case it was necessary to give the
server time to save the file but to no avail.

You're misunderstanding the error message. The file never made it to
the server, because the put() was never executed. The error occurred
at the -e line I asked you to put in, telling you that the file does
not exist in your local directory.
P.S. I tired explictly defining all my variables but ran into one
problem with one used for my e-mail routine $mail. The line in
question is:
$mail{From} = 'Data Upload <[email protected]>';
Here's the error it gave me.

Global symbol "%mail" requires explicit package name at line 147.

That line is not using a variable $mail. It is using the hash variable
%mail. If you tried to declare that variable with
my $mail;
you should change that to
my %mail;

$mail and %mail are two independent variables that have nothing to do
with one another. For more information, please see:
perldoc perldata

Paul Lalli
 
G

Gary E. Ansok

Hi All,

I'm trying to format a date and store it in a variable for a file
name. The file gets created but for some reason my FTP process sends
an empty file with the same name.

Here's how I'm formatting the date.

$file = "dms_nspwr_" . `date +%b_%d_%y_%H%M.txt`;

As has been stated elsewhere, you're probably better off doing the
date formatting within Perl.

But if you are calling an external command to do the work, there
is probably a trailing newline.

perldoc -f chomp

It's often a good idea to make sure that your variables contain
*exactly* what you think they should. I usually do something like
print "--$file--\n";
to check for extra characters.

If you're viewing the output through a browser, remember that browsers
tend to reformat the output and make whitespace (particularly newlines)
in the input harder, if not impossible, to see. Using something like
$file =~ s/\n/[NL]/;
before the print will make possibly-hidden characters more visible.

Gary Ansok
 
N

Nex_s

Hi Paul,

I'm not changing directories, at least not explicitly. The name
"dms_nspwr_2005_08_02_1404.txt" is the name of the file I expected. I
changed it from what I had and decided to use POSIX. I put the ftp
code into another file by itself and when I ran it, it found the file
and ftp'd it no problem. So I'm still at a loss as to why there's a
problem with my main script.

Chris
 
P

Paul Lalli

Nex_s said:
I'm not changing directories, at least not explicitly. The name
"dms_nspwr_2005_08_02_1404.txt" is the name of the file I expected. I
changed it from what I had and decided to use POSIX. I put the ftp
code into another file by itself and when I ran it, it found the file
and ftp'd it no problem. So I'm still at a loss as to why there's a
problem with my main script.

Chris,

At this point, the best advice I can offer is to pare your code down
to the shortest complete script that still exhibits the problem, and
then to paste that code here. If you are indeed using
POSIX::strftime(), then Gary's hint elsewhere in this thread is no
longer relevant (which is unfortunate, because I was about to remark on
that as well).

Paul Lalli
 
N

Nex_s

Chris,

At this point, the best advice I can offer is to pare your code down
to the shortest complete script that still exhibits the problem, and
then to paste that code here. If you are indeed using
POSIX::strftime(), then Gary's hint elsewhere in this thread is no
longer relevant (which is unfortunate, because I was about to remark on
that as well).

Paul Lalli


Hi Paul,

I finally figured out after all that head banging what the problem
was. I forgot to close the file that I was sending!!! ARGH!

Anyhow, thank you for your patients and help. My hope is the
information this post provided is not in vain.

Chris
 
P

Paul Lalli

Nex_s said:
Hi Paul,

I finally figured out after all that head banging what the problem
was. I forgot to close the file that I was sending!!! ARGH!

Anyhow, thank you for your patients and help. My hope is the
information this post provided is not in vain.

Chris,

I'm glad you got your problem resolved. For the future, I would just
like to point out that this is precisely the reason the Posting
Guildelines request that you post a short but *complete* script which
exhibits your problem. If that had been done in the first place, it's
likely we would have been able to diagnose the problem without all the
guesswork involved in the snippet of code you did show.

Regards,
Paul Lalli
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,736
Latest member
AdolphBig6

Latest Threads

Top