user1833983
user1833983

Reputation:

how to zip a folder at FTP location using FTPClient in java

I wanted to zip a folder which has some files in it and which is present at ftp location. How I can zip folder at FTP location.

 FTPClient ftp = new FTPClient();
 ftp.connect(hostname);
 ftp.login(user, pass);
 ftp.changeWorkingDirectory("myfolder"); //I wanted to zip this "myfolder"

Thanks.

Upvotes: 1

Views: 4077

Answers (3)

Martijn Hoogesteger
Martijn Hoogesteger

Reputation: 51

While the process of downloading the files, compressing them locally and uploading them will work exactly as you want, this can take a lot of time depending on your connection speed.

If you have SSH access to the machine, I'd highly recommend making use of that. You can use an SSH library for Java (like SSHJ) and run a zip command on the folder. This will make the server zip the files locally, which will be much faster.

Upvotes: 3

Tomasz Nurkiewicz
Tomasz Nurkiewicz

Reputation: 340708

Look at the list of FTP protocol commands - there is nothing about ZIP there. And FTPClient can only do what FTP protocol can. What you have to do is:

  • download the contents of a folder you want to ZIP
  • compress locally
  • upload, optionally deleting the original folder

Of course you can wrap this in a pseudo-FTP command in your code/library.

Upvotes: 0

SJuan76
SJuan76

Reputation: 24780

FTP only deals with File Transfer. So, you can download or upload a file, but nothing more. If you want do zip something, you will have to download it to a machine your control and zip it there. Alternatively, you can use other protocols to access the machine (ssh / remote desktop / telnet / whatever you implement) and zip it remotely, but that will not be through FTP.

Upvotes: 0

Related Questions