FTP search ,grep using perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FTP search ,grep using perl
# 22  
Old 04-24-2013
Quote:
Originally Posted by ajayram_arya
Where should we look for the appearing files.
They get put in the current working directory.
Quote:
I dont need any permission as we are not putting or getting any file . We are just verifying if the file exist
Oh. Smilie All right then. I'll change the program.
# 23  
Old 04-24-2013
Code

Thank you Corona688 . Really appreciate your time and patience
# 24  
Old 04-24-2013
Code:
#!/usr/bin/perl -w

use Net::FTP;

while($line=<STDIN>)
{
        chomp($line); # Remove newline from end of string
        push(@str, $line); # Add string to end of @str array
}

$ftp = Net::FTP->new("localhost");
$ftp->login('user', 'pass');
$ftp->cwd("path");
$ftp->binary;
#$flag=$ftp->mdtm($_);

my @filenames=$ftp->ls();
print " Total files:", $#filenames + 1, "\n";
$match=0;
foreach (@filenames)
{
        for my $s(@str)
        {
                if(index($_, $s) >= 0)
                {
                        print $_, " Size:[", $ftp->size($_), "]",
                                " Mtime ", scalar(localtime($ftp->mdtm($_))),
                                "\n";
                        $match++;
                }
        }
}

if($match == 0) { print "No files matched\n"; }

$ftp->quit();

# 25  
Old 04-24-2013
Code

Corona688. This works absolutely great . Hats off to you ...:-)

You are my Guru in programming...

---------- Post updated at 01:27 PM ---------- Previous update was at 01:17 PM ----------

This script is wonderful . Need one more help in the same script .

Now we got the match for list of files , size and modified time.

In addition to that :

Sorry for the confusion .

I want the output to redirect to a file.

Last edited by ajayram_arya; 04-24-2013 at 04:31 PM.. Reason: Change of code
# 26  
Old 04-24-2013
What do you mean 'updated dates'? Newer than what?
# 27  
Old 04-25-2013
Code

Sorry for the confusion ..

I wanted the output to be redirected to a file . Can you please help me on this

---------- Post updated at 03:01 PM ---------- Previous update was at 02:57 PM ----------

I got my answer...thank you

---------- Post updated 04-25-13 at 02:21 PM ---------- Previous update was 04-24-13 at 03:01 PM ----------

Corona688

how can i add the listfile inside the script itself and redirect the output to a log file in the script itself

Code:
./myscript.pl < listfile


Last edited by ajayram_arya; 04-25-2013 at 04:26 PM..
# 28  
Old 04-25-2013
At the top of the script,

Code:
my @str=( "12345", "67890", "12345678" );
open(OUT,">output.log");

Then change your print statements to
Code:
print OUT "something","else";

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to use a grep search to search for a specific string within multiple directories?

Lets say I have a massive directory which is filled with other directories all filled with different c++ scripts and I want a listing of all the scripts that contain the string: "this string". Is there a way to use a grep search for that? I tried: grep -lr "this string" * but I do not... (3 Replies)
Discussion started by: Circuits
3 Replies

2. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies

3. Shell Programming and Scripting

Perl - start search by using search button or by pressing the enter key

#Build label and text box $main->Label( -text => "Input string below:" )->pack(); $main->Entry( -textvariable => \$text456 )->pack(); $main->Button( -text => "Search", -command => sub { errchk ($text456) ... (4 Replies)
Discussion started by: popeye
4 Replies

4. Shell Programming and Scripting

Perl - use search keywords from array and search a file and print 3rd field when matched

Hi , I have been trying to write a perl script to do this job. But i am not able to achieve the desired result. Below is my code. my $current_value=12345; my @users=("bob","ben","tom","harry"); open DBLIST,"<","/var/tmp/DBinfo"; my @input = <DBLIST>; foreach (@users) { my... (11 Replies)
Discussion started by: chidori
11 Replies

5. 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

6. UNIX for Dummies Questions & Answers

recursive search and ftp

Could someone help me in recursive search and ftp'ing the files to remote server? The host machine will have /dir1/dira/list_of_files1 /dir1/dirb/list_of_files2 /dir1/dirc/list_of_files3 . . . so., I need to search from dir1 recursively (only one level down) and find all the files that... (1 Reply)
Discussion started by: brahmi
1 Replies

7. Shell Programming and Scripting

perl search and replace - search in first line and replance in 2nd line

Dear All, i want to search particular string and want to replance next line value. following is the test file. search string is tmp,??? ,10:1 "???" may contain any 3 character it should remain the same and next line replace with ,10:50 tmp,123 --- if match tmp,??? then... (3 Replies)
Discussion started by: arvindng
3 Replies

8. Shell Programming and Scripting

Perl: Search for string on line then search and replace text

Hi All, I have a file that I need to be able to find a pattern match on a line, search that line for a text pattern, and replace that text. An example of 4 lines in my file is: 1. MatchText_randomNumberOfText moreData ReplaceMe moreData 2. MatchText_randomNumberOfText moreData moreData... (4 Replies)
Discussion started by: Crypto
4 Replies

9. Shell Programming and Scripting

using finddepth in ftp to search for directories in perl

Hi all, I have script which downloads the build and copies onto the local machine I am able to download files in a directory, but unable to get the files in subdierctories. I am using finddepth to search for sub directories but I am unable to do so. Here is my code: ... (0 Replies)
Discussion started by: gurukottur
0 Replies
Login or Register to Ask a Question