How to synchronise FTP directory from command line?
Asked Answered
K

8

7

I have a website with PHP files and other. I would like to do one-click synchronisation between my local copy of a website and my website on the server. It would be nice if there was be a command line utility or plugin to Eclipse PDT to do this.

Kevel answered 28/3, 2009 at 18:27 Comment(3)
My OS is Windows, and server has a Linux.Kevel
Ok, you need a synchronization tool with command line support for windows. if you have python installed you could try ftpsync2d since it's freeBusse
code.google.com/p/ftpsync2dBusse
K
8

I've found WinSCP. It's FTP, free and Open Source: http://winscp.net/eng/docs/start

And it works from command line with comparision of files (to synchronise it)

Kevel answered 28/3, 2009 at 19:46 Comment(2)
WinScp worked nice to download updates but is there a way to get it to delete files that are no longer on the ftp server?Rodent
@Rodent synchronize -delete it seems?Endorsee
A
14

I would recommend lftp. It's a sophisticated, scriptable command-line FTP client.

 lftp has builtin mirror which can download or update a whole
 directory tree. There is also  reverse  mirror  (mirror  -R)
 which  uploads or updates a directory tree on server. Mirror
 can also synchronize directories between two remote servers,
 using FXP if available.

lftp -f mirror.sh

mirror.sh

open sftp://<username>:<password>@<ip address>
mirror -c /<source> /<destination>
exit
Archivolt answered 28/3, 2009 at 18:37 Comment(3)
That link is for the Linux version. Don't know if the Windows version is maintained anymore, but there's a copy of it here: redpark.posterous.com/lftp-for-windowsTristatristam
It's still maintained --- 2013-03-14: lftp-4.4.5 released. A performance bug fixed.Extensity
lftp link is gone now that posterous has gone :(Jeanett
K
8

I've found WinSCP. It's FTP, free and Open Source: http://winscp.net/eng/docs/start

And it works from command line with comparision of files (to synchronise it)

Kevel answered 28/3, 2009 at 19:46 Comment(2)
WinScp worked nice to download updates but is there a way to get it to delete files that are no longer on the ftp server?Rodent
@Rodent synchronize -delete it seems?Endorsee
B
6

There is a tool called FTP Synchronizer (for Windows) which can be ran from a command line. You can't synchronize files by FTP without using any FTP library. The more mature is this library has the faster it will synchronize files (for example it can cache already synched file info in it's internal database).

Don't like FTP Synchronizer? Google for alternative.

Busse answered 28/3, 2009 at 18:29 Comment(0)
E
2

I've been using scriptFTP on my dedicated windows servers for well over a year to synchronise my database backup directories with my local servers. It's an excellent product that allows you to script (to a pretty sophisticated level) and schedule virtually any FTP task.

I have no connection with the product - just an extremely impressed user. The product solves precisely the problem it's is designed to solve and has proven totally solid for me. It's commercial - USD$35 - but one of the best $35 I ever spent on software.

Extravasation answered 28/3, 2009 at 18:44 Comment(0)
H
1

PhpStorm just added two-way sync (over FTP and others) into their most excellent PHP IDE. This feature is in the current 3.0 EAP (beta), not in the 2.1 version.

Hutson answered 18/11, 2011 at 4:19 Comment(1)
I did read the full question, but the question is poorly written, seeing as the request for perhaps an IDE plugin is only added at the very end as a side-note. The title only mentions command line and it's the answer that comes up at the top on GoogleWilford
C
0

You could try Aptana (http://www.aptana.org/studio/download) wich provide a file transfert tool to synchronise a project with a distant server using FTP. You can use the script view to enable a nice feature : upload current file on save !

Chavaree answered 26/1, 2010 at 7:9 Comment(0)
T
0

I made a simple script

#!/bin/bash

FTPLOCALFOLDER=$1
FTPLINK=$2

ls "$FTPLOCALFOLDER" > "./filesdownloaded.txt"

curl -sS "$FTPLINK" | grep -oE "(?href=\").*?(?\")" | awk -F '"' '{print $2}' > "./filesinlink.txt"

grep -v -f "./filesdownloaded.txt" "./filesinlink.txt" > "./filestodownload.txt"

echo "Start downloading"
while read p; do
    echo "downloading..... $p from $FTPLINK$p"
    wget "$FTPLINK""$p" -O "$FTPLOCALFOLDER""$p"
done < "./filestodownload.txt"

You can use like:

./wgetSync.sh <LOCALFOLDER> <FTPLINK>

Trixie answered 21/7, 2021 at 15:44 Comment(0)
S
-3

Sounds to me like a perfect application for version control software. Pick mercurial or git and use it for both version control and synchronization within the directories on the two machines. Mercurial is more user friendly overall and has a smoother install and presence on windows, though setting up git on windows is no longer too much of a hassle either.

Sepal answered 15/12, 2011 at 23:46 Comment(1)
This is not an answer! He didn't ask "hey, I'm trying to sync FTP but please give me a different solution". This angers me so much. What about when people don't have access to using git, for example their terrible client has a terrible client who have a terrible IT company straight outta 1997 who only allow CPanel and MySQLAdmin access? If you think the people reading this have never heard of Git, please, go ahead and write a comment on the question. But it's not a solution to the question!Wilford

© 2022 - 2024 — McMap. All rights reserved.