Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Regular Coder
    Join Date
    Apr 2006
    Location
    UK, England
    Posts
    268
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Zipping folders via SSH

    Is it possible to ZIP a folder/directory via SSH?

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Are you connecting to a windows or unix/inux machine?
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    Regular Coder
    Join Date
    Apr 2006
    Location
    UK, England
    Posts
    268
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Unix Server

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    Your best bet then would be to just tar the directory. On the command line just type:

    tar cvf filename.tar directoryname

    You can try to create a zip file via the command line if your unix machine has the zip program installed. The tar program is more common on linux/unix and more likely to exist. To see if the zip program exists just type zip and hit enter. If it is there it should spit out some usage summary information. If it does not exist then it will tell you command not found.
    Last edited by Spookster; 12-06-2006 at 07:34 AM.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    Regular Coder
    Join Date
    Mar 2005
    Location
    D0u$h!t3 k4?
    Posts
    512
    Thanks
    2
    Thanked 5 Times in 5 Posts
    I'd agree with Spookster. Use the tar utility as Spookster indicated and then you would probably want it compressed, so I would recommend gzip:

    gzip -9 filename.tar

    That will create filename.tar.gz or filename.tgz (not sure which). The '-9' basically means compress more. I'm not sure whether that would be valid for your version of gzip, but if it is, I recommend using it to conserve storage space, assuming that is the goal.
    PHP Code:
    $hello file_get_contents('hello.txt'); echo $hello
    hello

  • #6
    Regular Coder
    Join Date
    Apr 2006
    Location
    UK, England
    Posts
    268
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Well, the main purpose is to create a ZIP of the directory to allow users to download it. Im not sure how many people are confident with .tar. Additionally, the directory itself is about 110Mb or so, Zipping the folder will reduce that size and keep everything together ready for downloading.

  • #7
    Regular Coder
    Join Date
    Apr 2006
    Location
    UK, England
    Posts
    268
    Thanks
    2
    Thanked 0 Times in 0 Posts
    I zipped the contents of the website as a test, but the outcome seems to be a HTML file with a .zip extention at the end?

    Does this mean its not supported?

  • #8
    Regular Coder
    Join Date
    Mar 2005
    Location
    D0u$h!t3 k4?
    Posts
    512
    Thanks
    2
    Thanked 5 Times in 5 Posts
    Most file archiving applications can handle gzipped tarball files, even ones such as WinZip, which focus specifically on a single archive format. You might also check for a zip utility instead of gzip:

    zip -r filename.zip directory

    The '-r' means to recurse the directories.
    To unzip, there should be a complementary unzip utility. That way, there is no need for tar. However, gzipped tarballs tend to yield better compression rather often (1.7M gzipped was 693K for me and zipped was 696K for me). bzip2'd (bzip2 is a different compression algorithm than gzip) tarballs are also possible, but gzip is faster and, in my experience, compresses better generally, though there have been exceptions in the past.
    PHP Code:
    $hello file_get_contents('hello.txt'); echo $hello
    hello

  • #9
    Regular Coder
    Join Date
    Apr 2006
    Location
    UK, England
    Posts
    268
    Thanks
    2
    Thanked 0 Times in 0 Posts
    So basically, in a nutshell, I should use:

    gzip -9 filename.tar

    I take it the WinZip or the Windows Uncompressing utility will see this as a normal zip file, and able to unzip it?

  • #10
    Regular Coder
    Join Date
    Mar 2005
    Location
    D0u$h!t3 k4?
    Posts
    512
    Thanks
    2
    Thanked 5 Times in 5 Posts
    Applications won't see a gzipped file as a normal zip file. Windows-native zip decompression will not be able to use it because it is not a ZIP file. However, nearly all third-party software such as WinRAR, WinZip, WinAce and 7-Zip (this one is 100% free and it works on Windows and Linux) will recognize such files and should be able to decompress the files inside.
    PHP Code:
    $hello file_get_contents('hello.txt'); echo $hello
    hello

  • #11
    Regular Coder
    Join Date
    Apr 2006
    Location
    UK, England
    Posts
    268
    Thanks
    2
    Thanked 0 Times in 0 Posts
    In that case Id rather use the traditional Zip compression simpily becuase its more common and users wont have trouble opening it.

    So, so far, Ive zipped a folder but, it ended up as zip.html?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •