Keep in sync your files with your server

A topic built around all the best posts and information from the site. It includes informative posts, links to resources, tips, tricks, ect... Do not post here unless it will become a resource based post.
Post Reply
User avatar
a_bertrand
Posts: 1536
Joined: Mon Feb 25, 2013 1:46 pm

Keep in sync your files with your server

Post by a_bertrand »

Web applications requires a web server (depending on the company / technology you use, it may be called application server) to be developed, tested and then used. Many new web developers have the tendency / bad practice to directly develop on their publicly visible website being a free or payed hosting.

I hope NOBODY here do that, and you all develop on your local machine to then upload once you at least tested it to see if it works! If you don't then you MUST (not should) install a web server on your PC (being Windows, Linux or OSX), and develop locally. Why? We shall discuss that another time maybe.

Anyhow, let's assume everyone is sane and develop on his own PC, and once the soft is at least partially tested, upload the changes on the server. Yet, that can be painful if you don't use Visual Studio for example and use the one click publish facility there. As most here use PHP or Node.JS (right?) this is hardly a solution. So how do you do it? Via an FTP or SFTP (for SSH connections) tool usually, but you have to remember which file you modified, and then push it to the server. Can be error prone and at least for me annoying.

If you run under Linux, the easiest solution would be rsync (enough tutorials are found on the net to see how it works). Keep in mind you may need to set a proper private / public key to authenticate yourself, beside that it should be ok.

If you are on Mac OSX, no luck, I will not help you with this exotic system ;)

If you are like me, running on Windows as desktop and your web server runs under Linux, here is how I solved the issue:
Download for free WinSCP: http://winscp.net/eng/download.php

This tools runs both as command line utility and as graphical interface. As GUI you can use it like a folder, where you connect to your host and drag drop the files or use the sync tool graphically. But if you are like me on the super lazy side of life, you may want to have a single click on an icon to sync your whole project.

1) To do so, I created and saved a session on the GUI side of the tool, with the password of my server saved in the session (yes it may not be a good option if your PC is used by multiple people).
2) Added the path of the WINSCP.EXE file in my windows PATH environment variable (look at http://www.computerhope.com/issues/ch000549.htm to see for example how to set a path)
3) Created a cmd file somewhere on my local disk with something like:

Code: Select all

winscp session_name /script="C:\winscp_commands.txt"
change session_name with the session you created on the GUI side
4) Create the file winscp_commands.txt with a content like:

Code: Select all

synchronize remote C:\local\site /www/remote/dir
bye
Keep in mind last line should be "bye" such to close the winscp session

Once this is done, you are up and running, and then starting your cmd file will lunch the sync of your local and remote directory. That should take you between 5 and 10 min to setup, and then only a double click to sync all your changes. Isn't that cool?

Comments, questions are welcome of course ;)
Creator of Dot World Maker
Mad programmer and annoying composer
User avatar
Dayo
Posts: 10
Joined: Tue Jan 07, 2014 3:16 pm

Re: Keep in sync your files with your server

Post by Dayo »

Ive been using SVN just lately to keep track of projects, on windows i use tortoise svn and when i need to update my linux server i just putty into it and update, each time i only need to edit the settings file(s) as currently i have 6 servers (two live and 4 testing) :?
User avatar
a_bertrand
Posts: 1536
Joined: Mon Feb 25, 2013 1:46 pm

Re: Keep in sync your files with your server

Post by a_bertrand »

I do use SVN and tortoiseSVN too, but for SVN has normally another goal, it allows you to keep tracks and history of your development. Think for example that you make a modification, and a couple of days later you discover that something doesn't work anymore. With the differences between the version you many be able to see what has been touched and more quickly fix the issue.

Also, I may not really want to have the SVN directories on my server or maybe my SVN contains more than what I want to install (docs, or photoshop files for example).
Creator of Dot World Maker
Mad programmer and annoying composer
Post Reply

Return to “Resources”