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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to put FTP process as a background process/job in perl?
# 1  
Old 07-15-2011
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
# 2  
Old 07-15-2011
Hi,
For any process to run in background in *nix systems you can use "&"
For Ex:
Code:
 firefox &

Regards,
Mayur
# 3  
Old 07-15-2011
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?
# 4  
Old 07-18-2011
Quote:
Originally Posted by pludi
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
# 5  
Old 07-18-2011
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:
Code:
#!/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";
}

# 6  
Old 07-19-2011
Quote:
Originally Posted by pludi
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:
Code:
#!/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
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Make background process interact with fg process

Hi, I have written a menu driven shell script in which as per the choice, I run the another script on background. For eg: 1. get info 2)process info 3)modify info All the operations have different scripts which i schedule in background using &. However I wish to display the error... (0 Replies)
Discussion started by: ashima jain
0 Replies

2. Shell Programming and Scripting

How to call a background process in perl?

Hi, I want to put the following code as a parallel or background process The program is as below: $n=10; #Count of files to be created. for($j=0;$j<=$n;$j++) { open(FH,">files_$j.txt") || warn "cannot create a file\n"; { print FH "count of file: $j\n"; #Sample data to be written. just... (5 Replies)
Discussion started by: vanitham
5 Replies

3. Shell Programming and Scripting

How can put a background process to the foreground

Hi, guys: I am working on my own shell using c. When I put a process into the background, how can I put it back to the foreground using tcsetpgrp? Thanks (3 Replies)
Discussion started by: tomlee
3 Replies

4. UNIX for Dummies Questions & Answers

Script to start background process and then kill process

What I need to learn is how to use a script that launches background processes, and then kills those processes as needed. The script successfully launches the script. But how do I check to see if the job exists before I kill it? I know my problem is mostly failure to understand parameter... (4 Replies)
Discussion started by: holocene
4 Replies

5. Shell Programming and Scripting

How to process and run a program in the background in perl?

Hi, I have a query about processing and running Perl program at the background. I have HTML file called Userform.html which accepts input from the user. As soon as input is given the contol goes to get.cgi (get.cgi does some processing and computing tasks). Actually get .cgi takes more... (0 Replies)
Discussion started by: vanitham
0 Replies

6. Solaris

background process

Hi When I run ./script.sh & the script runs in bg But when I close the telnet session, the script is killed also. any idea how to keep this script running? thx (4 Replies)
Discussion started by: melanie_pfefer
4 Replies

7. Shell Programming and Scripting

Perl Background Process - Finshed Yet?

I have a perl process I want to run in background in a cgi, but do not want to continue until process finished code looks like this. sub calc(){ do calculations return value } In another Perl program I call above function such as &calc(); I want to continue after process... (4 Replies)
Discussion started by: photon
4 Replies

8. Solaris

killing a unix job after the job process gets completed

Hi, Thanks in advance. i need to kill a unix background running job after that job process completes. i can kill a job by giving the following unix command kill -9 processid how to kill the job after the current process run gets completed ? Appreciate your valuable help. Thanks... (7 Replies)
Discussion started by: dtazv
7 Replies

9. Shell Programming and Scripting

killing unix job after the job process completes

Hi, Thanks in advance. i need to kill a unix background running job after that job process completes. i can kill a job by giving the following unix command kill -9 processid how to kill the job after the current process run gets completed ? Appreciate your valuable help. ... (1 Reply)
Discussion started by: dtazv
1 Replies

10. Shell Programming and Scripting

capture the process id when starting a background process

Hello all, How do I start a background process and save the process id to a file on my system. For example %wait 5 & will execute and print the process id. I can't figure out how to get it to a file. I've tried: > filename 0>filename 1>filename. Any assistance is most appreciated. Thanks, Jim... (10 Replies)
Discussion started by: jleavitt
10 Replies
Login or Register to Ask a Question