Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I am very2 new in PERL...I have a folder need to be transfered from one client to server....So, how Net::FTP doing all this things?...For ur information, the folder contains some data....How can i transfer the folder and it's contain using Net::FTP ?....anyone have idea?....

Replies are listed 'Best First'.
Re: Transfer Folder Using Net::FTP
by Joost (Canon) on Oct 14, 2004 at 09:43 UTC
    Assuming FTP is actually the protocol you want to use, by all means use Net::FTP.

    You can find documentation on installed perl modules by typing perldoc ModuleName, in your case perldoc Net::FTP.

    It says (amongst other things):

    SNOPSYS use Net::FTP; $ftp = Net::FTP->new("some.host.name", Debug => 0) or die "Cannot connect to some.host.name: $@"; $ftp->login("anonymous",'-anonymous@') or die "Cannot login ", $ftp->message; $ftp->cwd("/pub") or die "Cannot change working directory ", $ftp->message;
    ...
    put ( LOCAL_FILE [, REMOTE_FILE ] ) Put a file on the remote server. "LOCAL_FILE" may be a name or a filehandle.
    Personally, i'd probably use scp instead. It's much more secure, and with a properly configured key pair, all you need to do is
    scp -r localdir remote.host:/remote/dir
Re: Transfer Folder Using Net::FTP
by claree0 (Hermit) on Oct 14, 2004 at 09:42 UTC
    Why not show us what you've tried so far - it'll make it much easier to help.
      actually i have write some script that transfer a single file using Net::FTP...And its work...below i quote my script...
      > $ftp_server = "***.***.***.***"; > $login = "roime"; > $password = "roimepuniran"; > $upload_to_dir = "/flow/flowBig"; > $input_file = "/flow/netflow"; > $new_file_name = "lyidia.pl"; > > ================================================================= > > my $ftp; > print "Connect From : ", $addr->peerhost(); > #Display Message > > $ftp = Net::FTP->new($ftp_server, Debug => 1) or warn +"Cannot connect to the ftp host"; > > $ftp->login($login,$password)or die $ftp->message; > $ftp->pwd or die $ftp->message; > $ftp->cwd($upload_to_dir) or die $ftp->me +ssage; > $ftp->binary(); > > $ftp->put($input_file, $new_file_name) or warn "...Not upload..";
      Do u have any idea, how can i distribute tis script, by that way i can transfer a folder taht contains files, instead of a single file transfered...
        If you want to do it the easy way, then you could useNet::FTP::Recursive.

        However, if you want to improve your perl skills, then I'd suggest breaking down the process into steps:

        * Create the target folder on the FTP server
        * Find the filenames for the current directory that need to be transferred. I'm assuming that you're using Windows so `dir /b` would be one way of getting a list of filenames.
        * Transfer each of those files to the target server.

        If your folder contains sub-folders then you'll need to use recursion.