ftp files in perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting ftp files in perl
# 1  
Old 05-18-2009
ftp files in perl

Hi,

I am using NET::FTP in perl to tranfer files.
i have an array of files

Quote:
@files = $ftp->ls;
and then I m getting one bye one using foreach.

the problem is I m not gettng the complete list of files.
the program terminates after 2 files.
when I execute again it will transfer the remaining 2 files. ( i have 4 files in my array).


why so?
# 2  
Old 05-18-2009
are you checking return codes (status) of the operations?
Without seeing your code it's hard to say.
# 3  
Old 05-18-2009
maybe:

Code:
@files = $ftp->ls;
chomp(@files);#<-- might have newlines that need removing before processing
foreach(@files) {
   do something
}

# 4  
Old 05-19-2009
hi.

actually I have a directory tree and inside that i have the same subdir..

like..

X is a main dir.
and there are A,B,C sub dir and inside that two dir for each of A,B,C

X/A/aa
X/A/bb

X/B/aa
X/B/bb

X/C/aa
X/C/bb


the senario is.. i have to get files from all the "aa" directories and after trasferring move thm to "bb".

i am trying to achieve this with the following



Quote:
sub FTP {

my $ftphost = shift;
my $ftpuser = shift;
my $ftppass = shift;
my $ftpdir = shift;
my $ftpmvdir = shift;
my $localdir = shift;

my $ftp = Net::FTP->new("$ftphost");
$ftp->login("$ftpuser","$ftppass");
$ftp->cwd("$ftpdir");
@files = $ftp->ls;
chomp(@files); ##added after KevinADC's reply but not worked.
foreach $filename(@files){


$ftp->get("$filename", "$localdir$filename");
$ftp->rename("$ftpdir/$filename", "$ftpmvdir/$filename");
};

$ftp->quit;

};



foreach $dir ("A","B","C"){

FTP("$host","$USER","$PASS","$Dir/aa","$dir/bb","$LOCALDIR");


}

but i am facing the problem which i mentioned.
Pl help.

also, Is this the right and efficient way?

Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to see the status of all the ftp put & get files logs and curent ftp transfer status ?

How to see the status of all the ftp put & get files logs and curent ftp transfer status if any active ftp running in the background ? (2 Replies)
Discussion started by: i4ismail
2 Replies

2. Shell Programming and Scripting

How to ftp the files in perl.?

i want to upload two different files in to two different directories(path) on ftp server.but i am able to ftping only one at a time :(.. not both simultaneously. here i have connectd the ftp and use the binary mode to transfer the files $ftp = Net::FTP->new($ftphost, Debug => 0) or... (2 Replies)
Discussion started by: aarts
2 Replies

3. Shell Programming and Scripting

FTP from one directory to another using perl

Hi All I am stuck with a problem and i want your help, I have two directories dir1 and dir2 The files present in dir1 is a1,a2 a3 a4 What i want to is to FTP the files present in the dir1 to dir2 (with .txt extension at the end.) with the help of the Perl. The output expected is The... (12 Replies)
Discussion started by: parthmittal2007
12 Replies

4. HP-UX

[Solved] Unable to rename file in ftp server .Net:FTP perl

Hello All, I am trying to connect to ftp server and get the files. Also i need to rename the file in other ftp dir. rename method is not allowing me to rename the file in other dir. When i tried copy command by using net::FTP:FILE then perl says it is not installed. Can some body help me to... (2 Replies)
Discussion started by: krsnadasa
2 Replies

5. Shell Programming and Scripting

ftp in perl

Hi, I have three files in this /home/mani/ location. I would like to ftp to another server. could you please give perl for that requirement. Thanks, Mani (10 Replies)
Discussion started by: Mani_apr08
10 Replies

6. Shell Programming and Scripting

Perl FTP navigation

Hi Experts, I have this requirement to list dirs and files of an FTP server on regular basis. I was able to do it by following script: $ftpobj = Net::FTP -> new ("$ftpsrv") || die "Cannot connect to FTP $ftpsrv"; $ftpobj -> login("user","passwd"); $ftpobj -> cwd ("/root_dir"); @rootdir... (1 Reply)
Discussion started by: mtomar
1 Replies

7. Filesystems, Disks and Memory

Not able to FTP the files to a FTP server

Hi , We are facing a weird problem in our project. we need to send some xml & audio files to a remote FTP server from a Linux box, we are doing this in Perl script using Net::FTP->. Issue here is.. when FTPed the files using Perl scripts, only empty files ( 0 byte) are getting created on the... (2 Replies)
Discussion started by: kishorepotta
2 Replies

8. Shell Programming and Scripting

Ftp code in Perl

Hi All, i want to have a ftp function in my perl but i am unfamailiar with the perl syntax. Can any body help ? The ftp code below is in csh, can anybody help to convert this to perl with the same functionality ? foreach t (10.10.10.10 20.20.20.20) set USER = "xxx" set PASS = "zzz"... (21 Replies)
Discussion started by: Raynon
21 Replies

9. Shell Programming and Scripting

using perl to ftp

Hi all, I am trying to download a build from an ftp server. My problem is that my build contains sub folders and files within the sub folders. I can ftp a single file at a time, but it will be difficult to specify all the paths and download individula files. My build structure is: ... (2 Replies)
Discussion started by: gurukottur
2 Replies

10. UNIX for Dummies Questions & Answers

Perl, Pipes, and FTP

I am attempting to automate an ftp session in PERL by emulating the user and sending commands to ftp, but I am getting unexpected and unwanted results. Here is a portion code that illustrates the method I am attempting (this was just a shot in the dark): system("( echo open server sleep 1... (2 Replies)
Discussion started by: murdaugh
2 Replies
Login or Register to Ask a Question