Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > file name and FTP problem formatting date! Please Help!

Reply
Thread Tools

file name and FTP problem formatting date! Please Help!

 
 
Nex_s
Guest
Posts: n/a
 
      08-02-2005

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;

 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      08-02-2005
Nex_s wrote:
> 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

 
Reply With Quote
 
 
 
 
Nex_s
Guest
Posts: n/a
 
      08-02-2005

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 <>';
Here's the error it gave me.

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




Paul Lalli wrote:
> Nex_s wrote:
> > 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


 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      08-02-2005
> Paul Lalli wrote:
> > Nex_s wrote:
> > > 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.


<snip>

> > >
> > > $ftp->put("$file")
> > > 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...
> >

> 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 <>';
> 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

 
Reply With Quote
 
Gary E. Ansok
Guest
Posts: n/a
 
      08-02-2005
In article <. com>,
Nex_s <> wrote:
>
> 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
--
The recipe says "toss lightly," but I suppose that depends on
how much you eat and how bad the cramps get. - J. Lileks
 
Reply With Quote
 
Nex_s
Guest
Posts: n/a
 
      08-02-2005

> > > Nex_s wrote:
> > > > 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.

>



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

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      08-02-2005
Nex_s wrote:
> 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

 
Reply With Quote
 
Nex_s
Guest
Posts: n/a
 
      08-02-2005

> 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

 
Reply With Quote
 
Paul Lalli
Guest
Posts: n/a
 
      08-03-2005
Nex_s wrote:
> 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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using Net/FTP to download a file (FTP Error 550) Jeff Miller Ruby 0 03-26-2009 05:50 PM
FTP : Time problem (net/ftp) Vin Raja Ruby 0 06-07-2007 07:47 AM
ftplib question - ftp.dir() returns something and ftp.nlst() does not Nico Grubert Python 0 11-24-2005 02:00 PM
Net::FTP problems getting files from Windows FTP server, but not Linux FTP Server. D. Buck Perl Misc 2 06-29-2004 02:05 PM
name = name.substring(0, name.lastIndexOf('.')); Help please Jack-2 Javascript 3 12-24-2003 04:39 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57