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 8 of 8
  1. #1
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts

    Get the size of uploaded files

    My uploading code works perfectly. So why couldn't I get the $filesize by using the below code?

    Code:
    $ftp->mkdir("/uploads/$ext_folder", 0777) 
    or die "Can't create subfolder: $!\n";
    
    $ftp->cwd("/uploads/$ext_folder") 
    or die "Cannot change working directory ", $ftp->message;
    
    $ftp->put($upload_file, $filename) 
    or die "Uploading failed ", $ftp->message;
    
    my $filesize = -s "/uploads/$ext_folder/$filename";
    
    $ftp->quit;
    Last edited by camaross; 04-16-2011 at 10:28 PM.

  • #2
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts
    I tried
    Code:
    my $filesize = $ftp->size($filename);
    and it does not seem to work either. Weird.
    Last edited by camaross; 04-17-2011 at 01:34 AM.

  • #3
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by camaross View Post
    I tried
    Code:
    my $filesize = ftp->size($filename);
    and it does not seem to work either. Weird.
    if file transfer fail the remote file will be removed automatically. If you don't have strict and warnings you can miss this kind of things:

    Code:
    my $filesize = $ftp->size($filename);
    best regards

  • Users who have thanked oesxyl for this post:

    camaross (04-16-2011)

  • #4
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts
    Thank you.

    But I think the file transfer is successful, I can see the file and can download it back from my ftp site.

    Quote Originally Posted by oesxyl View Post
    if file transfer fail the remote file will be removed automatically. If you don't have strict and warnings you can miss this kind of things:

    Code:
    my $filesize = $ftp->size($filename);
    best regards
    Last edited by camaross; 04-17-2011 at 02:25 AM.

  • #5
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,872
    Thanks
    2
    Thanked 164 Times in 159 Posts
    "/uploads/$ext_folder" is the path on the remote server where you're "putting" the file, but are you sure it's the exact same path on the local server where you're attempting to extract the size?

    Are you wanting to check the file size on the local server or the remote server?

    Maybe what you're wanting is to change:
    Code:
    my $filesize = -s "/uploads/$ext_folder/$filename";
    to:
    Code:
    my $filesize = -s $upload_file;

  • Users who have thanked FishMonger for this post:

    camaross (04-17-2011)

  • #6
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts
    Thank you very much for the reply. I want to check the file size on the remote server.

    I just tried but it seems like the below code is not working either.

    Code:
    my $filesize = -s $upload_file;
    [/QUOTE]


    Quote Originally Posted by FishMonger View Post
    "/uploads/$ext_folder" is the path on the remote server where you're "putting" the file, but are you sure it's the exact same path on the local server where you're attempting to extract the size?

    Are you wanting to check the file size on the local server or the remote server?

    Maybe what you're wanting is to change:
    Code:
    my $filesize = -s "/uploads/$ext_folder/$filename";
    to:
    Code:
    my $filesize = -s $upload_file;

  • #7
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,872
    Thanks
    2
    Thanked 164 Times in 159 Posts
    There's no reason to expect the example I gave to return the size on the remote server. It looks at the local side.

    Saying "it doesn't work" is meaningless.

    What do you get from:
    Code:
    my $size = $ftp->size($filename);
    print "size: <$size>";
    or
    Code:
    my $size = $ftp->size("/uploads/$ext_folder/$filename");
    print "size: <$size>";

  • Users who have thanked FishMonger for this post:

    camaross (04-17-2011)

  • #8
    Regular Coder
    Join Date
    Jan 2011
    Posts
    136
    Thanks
    101
    Thanked 0 Times in 0 Posts
    I got it fixed guys.

    This is the trick: I need to add this before the "my $size = $ftp->size($filename);"
    Code:
    $ftp->binary;
    Thank you all for the help.
    Last edited by camaross; 04-17-2011 at 04:04 PM.


  •  

    Posting Permissions

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