FTP from one directory to another using perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FTP from one directory to another using perl
# 1  
Old 03-14-2012
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 files should come in dir2 as a1.txt, a2.txt, a3.txt, a4.txt
# 2  
Old 03-14-2012
what you tried so far ?

did you use any ftp module ?
# 3  
Old 03-14-2012
The code which i have tried so far is
Code:
use strict;
use Net::FTP;
use Date::Manip;

while (my $file = readdir(DIR)) 
 {
         # Use a regular expression to ignore files beginning with a period
         next if ($file =~ m/^\./);
         #FTP 
         ftpfile($file);
          if($ftp_status==0) 
         {
             print "FTP not successful.\n";
         }
         else 
         {
            print  "FTP successful.\n";
         }

    
}
sub ftpfile {
$file = @_;
    my $ftp = Net::FTP->new($config->getconf('FtpHost')) or die "Can't connect to FTP host: $@\n";
    $ftp->login($config->getconf('FtpUser'), $config->getconf('FtpPassword')) or die "Can't login to FTP Server\n";
    $ftp->cwd($config->getconf('PutDir')) or die "Can't change directory\n";
    $ftp->put($file) or die "Can't put $_ \n"; 
    $ftp_status=1;
    }

# 4  
Old 03-14-2012
what error you are getting ?
# 5  
Old 03-14-2012
It doesn't give the error but the file is not transferred.
Any new idea
# 6  
Old 03-14-2012
why you are assigning $ftp_status=1; ?
# 7  
Old 03-14-2012
Just for conformation that ftp for that document has been done sucessfully
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replicate remote directory to local directory with ftp

I have system that generate files every 1 hours , i only have ftp connection from my local server to remote . $ ls -al -rw-r--r-- 1 water None 0 Feb 7 18:09 a.0800 -rw-r--r-- 1 water None 0 Feb 7 18:09 a.0900 -rw-r--r-- 1 water None 0 Feb 7 18:09 a.1000 is there any perl / php... (3 Replies)
Discussion started by: before4
3 Replies

2. Shell Programming and Scripting

ftp whole directory

HI Guys, I have downloaded the oracle binaries from oracle.com, i have unziped them in a directory say OWB. I have to copy them to my windows server so i have ran the ftp command. It looks like i can ftp whole directory. Can you please get me the command to get all the files and... (7 Replies)
Discussion started by: guddu_12
7 Replies

3. Shell Programming and Scripting

FTP files from different directory from remote server to one directory in local

Hi All, I want to search for .log files from folders and sub folders in remote server and FTP them to one particular folder in the local machine. I dont want to copy the entire directory tree structure, just have to take all the .log files from all the folders by doing a recursive search from the... (3 Replies)
Discussion started by: dassv
3 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. Solaris

ftp default directory

how to change the default login directory for a specified user when ftp to unix machine. (1 Reply)
Discussion started by: mm00123
1 Replies

6. UNIX for Dummies Questions & Answers

can we ftp a directory

Hi guyz, Is there any way to ftp a whole directory structure. I mean is there any way using which I can get the whole directory ftpied including the subdirectories Thanks and regards, Gauravv (17 Replies)
Discussion started by: gauravgoel
17 Replies

7. UNIX for Dummies Questions & Answers

Downloading whole directory with FTP

Is it possible using FTP to download a whole directory and all subdirectories at once without having to go through every single file? Thanks, Tom (4 Replies)
Discussion started by: Pokeyzx
4 Replies

8. UNIX for Dummies Questions & Answers

ftp a directory

How does one ftp an entire directory from one Solaris 5.9 machine to another with out moving one file at a time? (4 Replies)
Discussion started by: DarkLord
4 Replies

9. Shell Programming and Scripting

FTP to read a directory

help needed ! I have an ftp script that read a directory for files with the *.*, problem is now that it returns a lot and now i will like to limit the data to get by only selecting the required files. All the files have and extension with the year date eg. bb039519.233. the .233 is the date of... (11 Replies)
Discussion started by: jikyj
11 Replies

10. UNIX for Dummies Questions & Answers

ftp-directory

Some users get on our server with ftp with a specific username (i.e. guest). The users guest has an own group. The user guest is in the path /usr/guests after login. How can I lock the user guest that he don't get up to the /usr treee. I tried to change the rights for the .. But it's not anymore... (1 Reply)
Discussion started by: arn_ch
1 Replies
Login or Register to Ask a Question