Link to home
Start Free TrialLog in
Avatar of E=mc2
E=mc2Flag for Canada

asked on

Modify FTP script

I would like to modify this FTP script below so that it does the following

1. Download any new files to the local directory.  (So the script needs to determine what it downloaded last time, so that it doesn't download it again, unless it it's easier to write the script so as to download everything it sees in the remote directory to the local directory and just overwrite any files which it sees, which is ok as well, in this scenario).

2. Does not delete the previous files from the remote directory.


@echo off
setlocal 

set password=xxxxxxxxxx
set /p password=<%~nx0:password
if not "%password%"=="" goto OK
set /p password=Enter password: 
echo %password%>%~nx0:password
:OK

set localdir=\\server1\main\
set remotedir=/out
set ftpserver=xxxxx.xxxxxxxxxxx.com
set username=xxxxxxxx

::del "%localdir%\*.*" /q

call :GetFtpFiles
call :ClearFTPFiles

exit /b

:GetFTPFiles
    (echo open %ftpserver%
    echo user %username% %password%
    echo bin
    echo cd %remotedir%
    echo lcd "%localdir%"
    echo mget *.*
    echo quit
    ) | ftp -n -i
    exit /b

:ClearfTPFiles
    (echo open %ftpserver%
    echo user %username% %password%
    echo cd %remotedir%
    (for /f "tokens=*" %%a in ('dir /b /a-d "%localdir%\*.*"') do @echo dele "%%~a")
    echo quit
    ) | ftp -n -i -d

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Bill Prew
Bill Prew

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The only way you can do this is to walk the directory of your remote FTP server + get file's last modified time.

This depends on the FTP server. Some provide this info. Some don't.

Then check all times against your local copy of files.

Or... you can just use rsync, which already does all this work for you.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of E=mc2

ASKER

Thanks to all, let me take a look.. and try the script..