Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Net::FTP - How Do I Read The Available Space On A Partition ???

Reply
Thread Tools

Net::FTP - How Do I Read The Available Space On A Partition ???

 
 
tommo_blade
Guest
Posts: n/a
 
      09-04-2006
Hello All,
I have read thru the perl docs for this module and I have
tried a few of the 'methods' available but as yet I have not been able
to get my script to pull the data I need from the server. basically I
want to know if there is enough 'available space' on a unix partition
prior to me FTP'ing a file to that host/partition, I have tried the
'ls' and 'dir' methods but I cannot get what I need. The data I need at
unix level can be gained by running a 'df -k' command which when run
returns the available disk space in the 'avail' column.

Does anyone know of any neat tricks to get this data.


cheers, Mark.

 
Reply With Quote
 
 
 
 
David Squire
Guest
Posts: n/a
 
      09-04-2006
tommo_blade wrote:
> Hello All,
> I have read thru the perl docs for this module and I have
> tried a few of the 'methods' available but as yet I have not been able
> to get my script to pull the data I need from the server. basically I
> want to know if there is enough 'available space' on a unix partition
> prior to me FTP'ing a file to that host/partition, I have tried the
> 'ls' and 'dir' methods but I cannot get what I need. The data I need at
> unix level can be gained by running a 'df -k' command which when run
> returns the available disk space in the 'avail' column.
>
> Does anyone know of any neat tricks to get this data.


This works:

----

#!/usr/bin/perl

use strict;
use warnings;

my $df_out = `df -k`;

foreach my $Line (split /\n/, $df_out) {
my ($Filesystem, $OneKBlocks, $Used, $Available, $UsePercent,
$MountPoint) = split /\s+/, $Line, 6;
print $Available if ($MountPoint eq '/'); # substitute whatever
criteria you are interested in
}

----

but I am sure that someone will come up with a nifty one-liner. Also, it
depends on your 'df' output having the same format as mine (tested on
Ubuntu and Mac OS X).


DS
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      09-04-2006
tommo_blade wrote:
> I have read thru the perl docs for this module and I have
> tried a few of the 'methods' available but as yet I have not been able
> to get my script to pull the data I need from the server. basically I
> want to know if there is enough 'available space' on a unix partition
> prior to me FTP'ing a file to that host/partition, I have tried the
> 'ls' and 'dir' methods but I cannot get what I need. The data I need at
> unix level can be gained by running a 'df -k' command which when run
> returns the available disk space in the 'avail' column.
>
> Does anyone know of any neat tricks to get this data.


Uh. Is this something you can do through FTP? Forget Perl for a
moment - can you do this with a normal ftp command line session? If
not, what makes you think you'd be able to do it with a Perl interphase
to the File Transfer Proticol?

Paul Lalli

 
Reply With Quote
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      09-04-2006
David Squire <> wrote in comp.lang.perl.misc:
> tommo_blade wrote:
> > Hello All,
> > I have read thru the perl docs for this module and I have
> > tried a few of the 'methods' available but as yet I have not been able
> > to get my script to pull the data I need from the server. basically I
> > want to know if there is enough 'available space' on a unix partition
> > prior to me FTP'ing a file to that host/partition, I have tried the
> > 'ls' and 'dir' methods but I cannot get what I need. The data I need at
> > unix level can be gained by running a 'df -k' command which when run
> > returns the available disk space in the 'avail' column.
> >
> > Does anyone know of any neat tricks to get this data.

>
> This works:
>
> ----
>
> #!/usr/bin/perl
>
> use strict;
> use warnings;
>
> my $df_out = `df -k`;
>
> foreach my $Line (split /\n/, $df_out) {
> my ($Filesystem, $OneKBlocks, $Used, $Available, $UsePercent,
> $MountPoint) = split /\s+/, $Line, 6;
> print $Available if ($MountPoint eq '/'); # substitute whatever
> criteria you are interested in
> }


According to the OPs words "want to know if there is enough 'available
space' ... prior to me FTP'ing a file to that host/partition" that would
have to be run on the remote system, through ssh perhaps.

No solution exists using only the FTP protocol. The designers of FTP
have wisely decided not to require that. At the time, there were
machines that measured disk space in odd-sized "words" or "pages".
How many bytes are 1000 36-bit words?

Not that any of this has a relation to Perl...

Anno
 
Reply With Quote
 
tommo_blade
Guest
Posts: n/a
 
      09-04-2006
To clarify, I need to get this data using the Net::FTP module and not
by some preliminary perl script as has been mentioned in this thread.
Does anyone know if there are any other add-on modules to the Net::FTP
module that could get this data, i.e. Net::FTP::Common etc, etc.

cheers, Mark.

 
Reply With Quote
 
John Bokma
Guest
Posts: n/a
 
      09-04-2006
David Squire <> wrote:

> tommo_blade wrote:
>> Hello All,
>> I have read thru the perl docs for this module and I have
>> tried a few of the 'methods' available but as yet I have not been able
>> to get my script to pull the data I need from the server. basically I
>> want to know if there is enough 'available space' on a unix partition
>> prior to me FTP'ing a file to that host/partition, I have tried the
>> 'ls' and 'dir' methods but I cannot get what I need. The data I need at
>> unix level can be gained by running a 'df -k' command which when run
>> returns the available disk space in the 'avail' column.
>>
>> Does anyone know of any neat tricks to get this data.

>
> This works:


No it doesn't, it suffers from a race condition as probably all
"solutions".

--
John Experienced Perl programmer: http://castleamber.com/

Perl help, tutorials, and examples: http://johnbokma.com/perl/
 
Reply With Quote
 
John Bokma
Guest
Posts: n/a
 
      09-04-2006
"tommo_blade" <> wrote:

> To clarify, I need to get this data using the Net::FTP module and not
> by some preliminary perl script as has been mentioned in this thread.
> Does anyone know if there are any other add-on modules to the Net::FTP
> module that could get this data, i.e. Net::FTP::Common etc, etc.


There is no reliable way, even if it was supported by FTP unless the ftp
server would stop all processes that can generate data on your partition.

While you request how much free space there is, the information will
already be outdated by the time you start the upload. During the upload
another process can generate data. Imagine two programs doing the same:

free space = 1GB

program 1 asks free space and gets 1GB
program 2 asks free space and gets 1GB
program 1 starts to upload 700 MB
program 2 starts to upload 700 MB
???
profit

--
John Experienced Perl programmer: http://castleamber.com/

Perl help, tutorials, and examples: http://johnbokma.com/perl/
 
Reply With Quote
 
Bob Walton
Guest
Posts: n/a
 
      09-04-2006
tommo_blade wrote:
....
> I have read thru the perl docs for this module and I have
> tried a few of the 'methods' available but as yet I have not been able
> to get my script to pull the data I need from the server. basically I
> want to know if there is enough 'available space' on a unix partition
> prior to me FTP'ing a file to that host/partition, I have tried the
> 'ls' and 'dir' methods but I cannot get what I need. The data I need at
> unix level can be gained by running a 'df -k' command which when run
> returns the available disk space in the 'avail' column.
>
> Does anyone know of any neat tricks to get this data.


Well, I don't know how "neat" it is, but you can use Net::FTP's quot()
method to execute a command on the remote system. I use it to chmod CGI
programs to executable on ISP systems that don't provide command line
access, for example (yeah, I know, I could get a better ISP). To get
the result of the command returned back to you, you will probably need
to redirect the STDOUT of the command to a file, then use the get()
method to get the file, then open and read it. I don't know if the
remote FTP server will run operating system commands with STDOUT
redirected -- you'll have to try it and see. You can check out how it
works with a command-line FTP client -- when you see you can do what you
want with a manual client, then implement it using Net::FTP.

You might be just as well off to do your put() and check the return for
an error.

HTH.

> cheers, Mark.


--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl
 
Reply With Quote
 
tommo_blade
Guest
Posts: n/a
 
      09-05-2006
Thanks to all who replied, I think I will go with the suggestion of
sticking the file in regardless and then checking that it is the same
size (->size()) as the source file.

 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      09-05-2006
tommo_blade schreef:
> Thanks to all who replied, I think I will go with the suggestion of
> sticking the file in regardless and then checking that it is the same
> size (->size()) as the source file.


If the transport is compressed, and the quota-calculation isn't, you
could test by first sending the file with all 0 bytes.

--
Affijn, Ruud

"Gewoon is een tijger."


 
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
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
dd - unequal speed from partition to partition, partition to file,file to partition bolega C Programming 1 03-28-2011 07:37 PM
Why Python style guide (PEP-8) says 4 space indents instead of 8 space??? 8 space indents ever ok?? Christian Seberino Python 21 10-27-2003 04:20 PM
Re: Why Python style guide (PEP-8) says 4 space indents instead of8 space??? 8 space indents ever ok?? Ian Bicking Python 2 10-23-2003 07:07 AM
Stack space, global space, heap space Shuo Xiang C Programming 10 07-11-2003 07:30 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