Skip to content

Instantly share code, notes, and snippets.

@lautarodragan
Last active March 20, 2024 23:03
Show Gist options
  • Save lautarodragan/664c92a2ce14c2c827279db40c1de288 to your computer and use it in GitHub Desktop.
Save lautarodragan/664c92a2ce14c2c827279db40c1de288 to your computer and use it in GitHub Desktop.
Perforce FTP Backups
@echo off
::::: p4ftp.bat :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::
:: A little Windows Batch Script to upload a Perforce ChangeList from console to a FTP host
::
:: first argument is the change list number, and is mandatory.
:: second argument is an optional "1" flag, indicating no confirmation is desired.
::
:: usage (from console): p4ftp.bat <cl> [1]
:: usage (from perforce visual client, p4v): Tools > Manage Custom Tools, click on New Tool,
:: fill in data, and under Arguments write "%C 1" (case sensitive, must be an uppercase c,
:: followed by a white space and the flag one)
::
:: limitations:
:: works only for straight-forward mappings
:: directory structure must already exist on the server, this script doesn't create the folders
::
:: On Github: https://github.com/lautarodragan/p4ftp
:: On Build Failure: http://buildfailure.wordpress.com/2013/05/15/windows-batch-script-ftp-upload-a-perforce-changelist/
::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
REM Constants
set ftp_host=github.com.ar
set ftp_username=user
set ftp_password=pass
set ftp_root=public_html
set p4root=C:/Perforce Workspaces/project
REM Arguments
if "%1"=="" (
echo Changelist number not specified.
exit /B n
)
REM Setup
Setlocal EnableDelayedExpansion
cd /D %p4root%
REM Confirmation
if not "%2"=="1" (
echo changelist %1 has the following files:
for /f "tokens=2 delims=# " %%g in ('p4 describe %1 ^| find "... //"') do (
Setlocal EnableDelayedExpansion
set line=%%g
echo ...!line:~9!
)
set /p confirmation=Confirm upload? Yes/No:
if not !confirmation!==yes (
echo Cancelled.
exit /B n
)
echo Uploading...
)
REM The Magic
echo user %ftp_username% %ftp_password% > ftp.dat
echo cd %ftp_root% >> ftp.dat
for /f "tokens=2 delims=# " %%g in ('p4 describe %1 ^| find "... //"') do (
Setlocal EnableDelayedExpansion
set line=%%g
set filepath=!line:~9!
set filepath=!filepath:main/=!
echo put "!filepath!" "!filepath!" >> ftp.dat
)
echo close >> ftp.dat
echo quit >> ftp.dat
ftp -n -s:ftp.dat %ftp_host%
del ftp.dat

p4ftp

A little Windows Batch Script to upload a Perforce ChangeList from console to a FTP host

First argument is the change list number, and is mandatory.
Second argument is an optional "1" flag, indicating no confirmation is desired.

Usage

From console

p4ftp.bat <cl> [1]

From perforce visual client, p4v

  • Tools > Manage Custom Tools
  • click on New Tool
  • fill in data
  • under Arguments write "%C 1" (case sensitive, must be an uppercase c, followed by a white space and the flag one)

Limitations

  • works only for straight-forward mappings
  • directory structure must already exist on the server, this script doesn't create the folders

On Build Failure: http://buildfailure.wordpress.com/2013/05/19/windows-batch-script-ftp-upload-a-perforce-changelist/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment