Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking free space on FTP server

Tags:

java

build

ant

ftp

I am running a build script in which three executable files (100mb each) are uploaded to an FTP server.

The first upload can fail due to an FTP server space problem so our build process fails. This means I have to free some space from the server and run the build script again which is waste of time. I'd like to check the FTP size before uploading the exe to make sure space is there. If sufficient space is there then upload otherwise prompt user for input.

How can I check the FTP size in an ant script.

like image 435
Piyush Avatar asked Feb 05 '26 07:02

Piyush


2 Answers

As discussed in the comments, you can write a shell script (assuming the FTP server is a linux box) along the lines of:

#!/bin/bash

FTPDIR="/path/to/ftp/dir"
echo `df -kl / | tail | awk '{print $4}'` > ${FTPDIR}/free_space.txt

Make sure you replace path/to/ftp/dir with the actual path to the directory you will be downloading from.

Add that script to the server's crontab (crontab -e) and let it run every hour (0 * * * *) or so. You can download the free_space.txt file which contains the hourly updated free space of the FTP server.

like image 142
Lewis Norton Avatar answered Feb 07 '26 21:02

Lewis Norton


FTP servers usually do not allow this, but you can try the command:

ftp> site df -kl

However, I suggest you to schedule a script on the FTP server which writes to a TXT file the current free space (which in turn you may read from your client).

like image 39
Sga Avatar answered Feb 07 '26 21:02

Sga



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!