#!/usr/bin/perl -w use strict; ################################################################################# # # # Author: Michael Alessio malessio@perforce.com # # # # This script is provided as a prototype only and I do not garantee that it # # will work for you. While feedback and bug reports are apreciated, I do not # # garantee that I will address them (but I might :-) # # # # This script is intended for persons doing web site development that do # # not have file system access to their web server. It will sync a # # workpsace, then push the files synced to an ftp site. It will also # # delete files from the FTP site if the synced revision was deleted. # # # # Caveat: # # The FTP PUT operation will fail if the destination directory does not # # exist on the FTP server. I hope to fix that later. # # # # Usage: # # 1) Create a workspace that duplicates the directory structure that you # # first see when logging on to your FTP site. # # 2) Edit the variables below to reflect your setup # # 3) Only ever sync this workspace using this script. If you do accidentally # # manually sync this workspace, then then edit the indicated line below to # # force a re-sync (will also force a PUT of every file in your workspace to # # your FTP site) # # # ################################################################################# my $p4 = 'p4 -s -p localhost:1666 -u username -c workspacename'; # Supply your own port, user, and workspace here my $ftpfile = "c:\\ftpPut.ftp"; # Temporary file where FTP commands will be written my $ftpUser = 'anonymous'; # Supply your FTP Username my $ftpPW = 'me@nospam.org'; # Supply your FTP Password my $ftp = "ftp -s:$ftpfile ftp.myserver.com"; # Supply your own FTP site my $WorkspaceRoot = ''; my $regexWorkspaceRoot = ''; my $depotPath = ''; my $action = ''; my $filename = ''; my $remotefilename = ''; my @results; my $result = ''; my $i = 0; $result = `$p4 info`; ($WorkspaceRoot) = ($result =~ /info: Client root: (.*)/); $regexWorkspaceRoot = "$WorkspaceRoot\\"; $regexWorkspaceRoot =~ s/\\/\\\\/g; @results = `$p4 sync`; # if you have accidentally synced your workspace then add a -f to this command if ($results[0] =~ /error: File\(s\) up-to-date./) { print "No ftp pushing needed" } else { open(FTP, "> $ftpfile"); print FTP "$ftpUser\n"; print FTP "$ftpPW\n"; while (not($results[$i] =~ /exit:/)) { ($depotPath,$action,$filename) = ($results[$i]=~ /^info: (.*)#\d* - (\w*) .*$regexWorkspaceRoot(.*)/); $remotefilename = $filename; $remotefilename =~ s/\\/\//g; if ($action eq "deleted") { print FTP "del \"$remotefilename\"\n"; } else { print FTP "binary\n"; print FTP "put \"$WorkspaceRoot\\$filename\" \"$remotefilename\"\n"; } $i++; } print FTP "bye\n"; close FTP; print `$ftp`; }