1

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.

3 Answers3

3

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.

0

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.

SJuan76
  • 24,532
  • 6
  • 47
  • 87
0

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.

Tomasz Nurkiewicz
  • 334,321
  • 69
  • 703
  • 674
  • Thanks all for the help.Local in my eclipse I can give local file path to download file as C:\myfolder. But if I deploy my application on some instance it will not understand my C:\myfolder, in that case how I will provide this path ? –  Nov 19 '12 at 02:01
  • @user1833983: just create a temporary directory, wherever it is suppose to be, see: http://stackoverflow.com/questions/617414 – Tomasz Nurkiewicz Nov 19 '12 at 07:30