Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts

    Why isn't the second $ftp->size working?

    I am uploading two files into the FTP site. It is so strange. I can upload both files but I can only get the filesizefor the first one. What is wrong here?

    Thank you very much for any hints.

    This part of the code uploads the first one:
    Code:
    my $filename    = $query->param("Userfile0"); 
    my $upload_file = $query->upload("Userfile0"); 
    
    my ( $name, $path, $extension ) = fileparse ( $filename, '\..*' ); 
    $filename = $name . $extension; 
    
    $filename =~ tr/ /_/;  # replace spaces with underscore
    $filename =~ s/[^$safe_filename_characters]//g;    # remove unsafe characters such as slash
    
    $ftp->put($upload_file, $filename) 
    or die "Uploading failed ", $ftp->message;
    
    my $size = $ftp->size($filename);
    This part of the code uploads the second one:
    Code:
    my $filename1 = $query->param("Userfile1"); 
    
    if ($filename1){
    
    my $upload_file1 = $query->upload("Userfile1"); 
    
    my ( $name1, $path1, $extension1 ) = fileparse ( $filename1, '\..*' ); 
    $filename1 = $name1 . $extension1; 
    
    $filename1 =~ tr/ /_/;  # replace spaces with underscore
    $filename1 =~ s/[^$safe_filename_characters]//g;    # remove unsafe characters such as slash
    
    $ftp->put($upload_file1, $filename1) 
    or die "Uploading of $filename1 failed ", $ftp->message;
    
    my $size1 = $ftp->size($filename1);
    
    }
    Last edited by camaross; 05-18-2011 at 12:09 AM.

  • #2
    New Coder
    Join Date
    Oct 2006
    Posts
    68
    Thanks
    0
    Thanked 28 Times in 28 Posts
    Your call to size is within an if statement. Therefore, my $size1 is declared and then immediately goes out of scope.

    Code:
    my $size1 = $ftp->size($filename1);
    If you used $size1 later on, it should have returned a strictures error as long as you had use strict; turned on. Unless you have it declared earlier for some reason.

    If the code is identical, i'd recommend that you put the file processing in a loop so that you can manage both files with the same code.

    Finally, don't know why the subject of your thread says "Resolved" already.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •