How to unzip files via an FTP connection?

20

6

I have connected to my remote server via FTP and I got a directory listing. I have few zip files in the list.

Is it possible to unzip the file (Ex: test.zip)?. If yes, what is the command?

Hearaman

Posted 2012-09-26T06:42:46.807

Reputation: 303

after unzip install, command is unzip test.zip – None – 2012-09-26T06:45:28.553

...through ubuntu terminal... Just for the sake of it, that's not a connection option, that's an application. Did you connect via SSH, SFTP, FTP or some other means? – Bobby – 2012-09-26T07:13:36.870

This is ftp connection – Hearaman – 2012-09-26T07:31:21.623

Answers

16

It is not possible to unzip files over an FTP connection. FTP stands for "File Transfer Protocol", which was only designed to transfer and partly manage files on the remote end, but not to execute commands. To unpack an archive you'd have to execute a program like tar, bzip2 or similar, but that's not possible via a FTP connection.

You need another session which allows you to execute commands, like SSH. Or you unpack the archive on your machine and transfer the contents via FTP, which will be considerable slower if you have a large number of small files because of the overhead of FTP.

Bobby

Posted 2012-09-26T06:42:46.807

Reputation: 8 534

are there any softwares(linux) to unzip my files. – Hearaman – 2012-09-26T07:49:27.530

@Hearaman the command unzip. – Kruug – 2013-05-06T17:55:46.797

16

Little bit out of context answer but surely works. If you are running a Apache + php on that ftp directory then upload your zip file in that folder and create extractor.php:

$zip = new ZipArchive;
if ($zip->open('my_zip.zip') === TRUE) {
    $zip->extractTo('/path/to/my/zip');
    $zip->close();
    echo 'ok';
}

and then hit url eg: http://example.com/extractor.php bingo php will extract that zip for you.

Touqeer Shafi

Posted 2012-09-26T06:42:46.807

Reputation: 261

very useful script, you can use getcwd() for this folder aka unix pwd in the script – Stepo – 2018-12-10T13:46:43.150

3

You can do it if you mount ftp resource using curlftpfs:

curlftpfs ftp://ftp.server.org/ /path/to/mountpoint

then

unzip /path/to/mount/test.zip

jet

Posted 2012-09-26T06:42:46.807

Reputation: 2 675

2If won't save you nothing of transfer, because the unzip process will be done by your computer and not on the server which should be the optimized way to do it. – NetVicious – 2016-10-06T11:17:21.093

2

You can use unzip after running sudo apt-get install unzip.

fraabye

Posted 2012-09-26T06:42:46.807

Reputation:

i have installed the unzip package using sudo apt-get install unzip. But it is giving me invalid command – None – 2012-09-26T06:48:47.273

You can use it like "unzip filename.zip -d /destination" – None – 2012-09-26T06:50:32.650

2

Sanath

Posted 2012-09-26T06:42:46.807

Reputation: 121

This was super easy. I uploaded the zip file via FTP and then used SSH to access the server where I ran the simple command unzip nameoffile. Thanks. – fmz – 2014-06-17T14:33:21.290

2

Is your goal to unzip it on the external server, or do you want to pull the archive contents to your own computer?

The first case is not solved by FTP, but by SSH or similar techniques as described in other answers.

If you just want to get the unzipped contents "directly" to your own computer without first explicitly transferring the files and then unzipping, you could e.g. mount the FTP site as a folder and unzip it as a normal zip file to a location on your local computer. This will in practice stream the file contents directly to the unzip program, so you technically do transfer the whole file, but only in its zipped state (presumably saving traffic) and the contents will appear directly on your local computer without the explicit intermediate step.

I don't know how the zip file format is specified concerning just unzipping a part of a zip file; if you need to transfer the whole file nevertheless or only the compressed part corresponding to that file. I don't see any real technical reasons as to why it wouldn't be possible to do this kind of selective transfer (the FTP protocol allows only transferring partial files to enable resuming).

Daniel Andersson

Posted 2012-09-26T06:42:46.807

Reputation: 20 465

0

As far as I know some FTP servers are set up to automatically unzip files on download. For example, the server lists a file named test.txt.gz, with your ftp client you can type get test.txt, the server then sends the file through unzip.

This is the answer that can be read right before download begins : 150 Opening ASCII mode data connection for /usr/bin/gzip.

Kay

Posted 2012-09-26T06:42:46.807

Reputation: 1

-1

you can use tar command

tar -xfz test.zip

Sreejith B Naick

Posted 2012-09-26T06:42:46.807

Reputation: 99

1This command works on the local terminal, but can NOT be run over an FTP connection (even when using the site FTP command) – JonathanDavidArndt – 2018-02-23T16:24:27.720

4To remember the letters: eXtract Zee Files – Canadian Luke – 2012-09-26T07:01:31.107

invalid command is coming in my console. – Hearaman – 2012-09-26T07:04:09.473

with -xzf instead of -xfz? – HaydnWVN – 2012-09-26T07:37:40.783

(Requires root permision)install tar by sudo apt-get install tar – Sreejith B Naick – 2012-09-26T11:24:12.597

try to open the ftp link in Nautilus,right click on the zip file, and check whether there is "extract here" option. – Sreejith B Naick – 2012-09-26T11:30:13.130