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

Hello Folks

I have been trying to create zip file of a folder containing some files on FTP server from client machine. I'm stuck at is it possible with any perl module?

I tried with Net::FTP, Net::SFTP, Net::SFTP::Recursive but every module has its limitation over file handling

I wanted to create Perl script which will run on client machine(OS:Windows7) and established FTP connection on Windows Server 2012 r2

While in FTP session script read directory and make zip of it and download to client machine

Please any suggestion..!!

Thanks in advanced

use strict; use warnings; use Net::FTP; use Net::Cmd; my $host = "1.1.1.1"; my $user = "Username"; my $pass = "Password"; my $dir = "/07-Nov-2016/Documents"; my $zipfile = "Documents_11222016.zip"; my $f = Net::FTP->new($host) or die $!; if($f->login($user, $pass)){ print "Connection established\n"; $f->binary(); $f->cwd($dir); # want logic to zip Document folder as Documents.zip $f->get($zipfile, "C:\temp\".$zipfile) or die $!; } else{ die $!; }

Replies are listed 'Best First'.
Re: How to create zip on FTP server from client machine using perl
by Corion (Patriarch) on Nov 22, 2016 at 08:38 UTC

    Does your FTP server support creating a ZIP file for you? Does this feature work with any other client you know?

    If yes, look at Net::FTP and its ->cmd ->quot function to do the same from Perl.

    If no, you will have to download all files yourself using Net::FTP and then use Archive::Zip to create the ZIP file on your client.

      Does your FTP server support creating a ZIP file for you?That I want to figure out

      Does this feature work with any other client you know?Not tested with other client

      On windows server 2012 r2 i.e. FTP server configured which not have Zip as utility in cmd but I install 7z on it

      how can I use that?

        It sounds like you should research what FTP is. The ability you require does not exist in standard FTP. Perhaps you want to connect to the server via other means and create a zip file? hint.

        You will need to research what the magic command is to make your FTP server zip up files and send you a ZIP file.

        Then you can use the ->quot method to send that command to your server.

        As marto already said, this is more a question into research on FTP servers than it is a question about Perl and Perl modules.

Re: How to create zip on FTP server from client machine using perl
by marto (Cardinal) on Nov 22, 2016 at 11:53 UTC

    It's customary to mark updates to your post, take a look at How do I post a question effectively?/PerlMonks for the Absolute Beginner. If you look at the documentation for Net::FTP the get method states "Get REMOTE_FILE from the server and store locally...". Your question was "I have been trying to create zip file of a folder containing some files on FTP server from client machine.", but your code shows logging into a server and retrieving a file. If you are trying to create a zip file of a directory on the FTP server, you won't be able to use FTP to do this. If you want to retrieve a directory from a server and create a zip file you can use Net::FTP to transfer the files then create a zip file. If you just want to create a zip file on the FTP server see my previous reply.

      I want to create zip file on ftp server first of existing directory call Documents and then download it to local client machine

      I installed 7zip on server how can I send command to execute 7z a -tzip "07-Nov-201l\Documents.zip" "07-Nov-201l\Documents"

      You mention in previous reply use ->cmd can you tell me syntax for it.

        I don't see a cmd method, but there is quot(CMD,[ARGS]), so perhaps something like:

        $f->quot('7z', 'a', '-tzip', '07-Nov-201l\Documents.zip', '07-Nov-201l\Documents');
        But God demonstrates His own love toward us, in that while we were yet sinners, Christ died for us. Romans 5:8 (NASB)