How to put FTP process as a background process/job in perl?

Hi,

I am using net::ftp for transferring files now i am trying in the same Linux server as a result ftp is very fast but if the server is other location (remote) then the file transferred will be time consuming.

So i want try putting FTP part as a background process. I am unaware how to do this. I am using Perl and net::ftp package in Linux server.

How can i handle this in Perl?

Any ideas how to put ftp process as an background process?

Regards
Vanitha

Hi,
For any process to run in background in *nix systems you can use "&"
For Ex:

 firefox & 

Regards,
Mayur

Are you using the FTP transfer as part of a larger script, or is this the only thing the script does? Do you need any information from the script once it's done?

Hi,

Yes i am using FTP as a part of a larger script many things are done before this i.e. the data is retrieved from the data base and processed and the results are in the file when the complete results in the file then the FTP script is called. Once the FTP is successful i would return the status weather success or failure. Yes Success / failure information is very much required.

How can i handle in Perl? Is it possible

Regards
Vanitha

Do you want to do any additional processing while the file is being transferred? If not, I don't see why the transfer process should be separated from the main process.

Otherwise, here's a small script on how to use fork:

#!/usr/bin/perl -w

use strict;
use warnings;

print "Parent script\n";

my $pid = fork();
if ( $pid == 0 ) {
    print "Child script started\n";
    sleep 5;
    print "Child script ending\n";
    exit int( rand(255) );
}
elsif ( $pid > 0 ) {
    print "Parent script, child has PID $pid\n";
    waitpid( $pid, 0 );
    print "Parent script, child exited with status " . ( $? / 256 ) . "\n";
    exit 0;
}
else {
    print "Error when forking: $!\n";
}

Hi,
Thanks for your reply. My sense is that FTP should not be depended on the main process it should be as an background process. Yes there are chances of additional processing while the file is being transferred

Suppose my main program is main.pl and ftp is callftp.pl how do i utilize the above program and put callftp.pl as an background program?

Regards
Vanitha