A good[ish] website
Web development blog, loads of UI and JavaScript topics
Sometimes you need to move a ton files to a server, it’s 100 times faster to move as one chunk than one-by-one.
Ideally you have an SSH
access to your server (SSH
means Secure shell, read more about SHH here). Meaning you log into your server using the Terminal (Mac) or Putty if your on Windows. If you don’t have SSH
access, don’t worry, there is another way (more on that at the end of this article).
If you’re not sure how to login, here’s how that happens:
$ ssh username@domainname.com
Using a custom port (good idea) and an ssh key:
$ ssh -i ~/.ssh/id_rsa_foo -p 5555 username@domainname.com
Or using an IP rather than a hostname:
$ ssh -i ~/.ssh/id_rsa_foo -p 5555 username@12.12.12.123
That should get you in.
There’s many compression algorithms, zip is one of the popular ones. It uses the .zip
file extension.
If you don’t have zip installed, in Ubuntu and Debian you can install it with apt-get:
$ sudo apt-get install zip
A single file:
$ zip my-database.zip my-database.sql
When zipping a directory, use the recursive flag:
$ zip -r my-directory.zip my-directory/
Here’s the breakdown:
-r
my-directory.zip
my-directory/
$ unzip archive.zip
This post looks into the GNU tar program for Gzipping (there’s also others). GNU tar supports compression through gzip and bzip2. It’s very similar to zip, but slightly more effective. Gzip files have .tar.gz
or .tgz
extension, and are usually referred to as tarballs.
The tar
command syntax is more nebulous than the straightforward zip command, but there’s an effective memory rule:
Compress a directory with tar files (compress ze files):
$ tar -czf target-file.tar.gz /source/directory
A add v
for verbose output: -czvf
.
Decompress a file (xtract ze vucking files):
$ tar -xzvf compressed-file.tar.gz
If you’re dealing with a ShitServer™ (shared hosting) which only provides ftp or sftp access, then you obvs can’t run any commands on the server. Below are few possible options.
Sometimes a shared hosting server will provide a control panel (Plesk etc.) where you usually have a file browser that can unzip files.
Most shared hosting servers have PHP installed, so you can try to use a PHP script for unzipping.
This PHP unzipper1.zip script has worked for me in the past. Unzip it and ftp that sucker to your server, then navigate to ithttps://yourdomain.com/index2.php
.
Or maybe this similar PHP script works better for you. I haven’t tested that, though.
PHP also has an ability to unzip files natively. Likewise haven’t tried this one but maybe it’s what you’re looking for:
// Assuming `file.zip` is in the same directory as the executing script.
$file = 'file.zip';
// Get the absolute path to $file.
$path = pathinfo(realpath($file), PATHINFO_DIRNAME);
$zip = new ZipArchive;
$res = $zip->open($file);
if ($res === TRUE) {
// Extract it to the path we determined above
$zip->extractTo($path);
$zip->close();
echo "WOOT! $file extracted to $path";
} else {
echo "Doh! I couldn't open $file";
}
The PHP snipped is picked up from this StackOverflow post.
Comments would go here, but the commenting system isn’t ready yet, sorry.