Topic "backup local directory to ftp Server with adding actual "date-Time" to remote directory-Name"

Author Message
bogomil
[View user's profile]

Joined: 2016-11-15
Posts: 3
hello everybody,
i have to do automated daily backup of local "data"-directory of a cash register system to a ftp-server at a specific time (06:00 a.m)
on ftp-server there should be added actual "date-Time" to remote directory-Name. e.g. "data" >>> "2016-11-15_0139_data"
can you provide me with a sample-script where similar problems have been solved before or give me some hints - many thanks in advance Wink
Advertisements
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26553
Location: Prague, Czechia
Code:
open ftp://username:password@ftp.example.com
put C:\local\path\data /remote/path/%TIMESTAMP#yyyy-mm-dd%_data
exit


See
https://winscp.net/eng/docs/guide_automation
https://winscp.net/eng/docs/scripting#timestamp
Wt

Guest


I need the same thing but only in the opposite direction. So, I need to schedule my PC to connect to remote FTP, collect all the files & folders there and copy those to my HDD at certain interval. The most important thing is that every time it collect the data, it create new containing folder with date&time stamp in folder name on a local drive so I could have multiple backups without overwriting the old ones.

Thanks in advance[/code]
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26553
Location: Prague, Czechia
The solution is the same:

get /remote/path/* C:\local\path\data\%TIMESTAMP#yyyy-mm-dd%

Except that WinSCP cannot create the target local directory for you. You have to create it before starting WinSCP.
E.g. from a wrapper batch file or PowerShell script.

You can still use WinSCP to generate the directory name for you:
https://winscp.net/eng/docs/script_formatting_timestamp_batch_file

Code:
rem Create new local directory
set TIMESTAMP_FORMAT=yyyy-mm-dd
for /F "tokens=* USEBACKQ" %%F in (`winscp.com /command "echo %%TIMESTAMP#%TIMESTAMP_FORMAT%%%" "exit"`) do set TIMESTAMP=%%F
mkdir C:\local\path\data\%TIMESTAMP%

rem Run WinSCP to download files to the newly created directory
winscp.com ...
bogomil
[View user's profile]

Joined: 2016-11-15
Posts: 3
martin wrote:
Code:
open ftp://username:password@ftp.example.com
put C:\local\path\data /remote/path/%TIMESTAMP#yyyy-mm-dd%_data
exit


See
https://winscp.net/eng/docs/guide_automation
https://winscp.net/eng/docs/scripting#timestamp


many thanks for help - i tested script - but remote folder was not resolved with "time-date-stamp" - remote folder appears as follows:

/remote/path/%TIMESTAMP#yyyy-mm-dd%_data

what can i do? - thank for help in advance ...
martin
[View user's profile]
Site Admin
Joined: 2002-12-10
Posts: 26553
Location: Prague, Czechia
Your duplicate post:
https://winscp.net/forum/viewtopic.php?t=24267
Advertisements

You can post new topics in this forum






Search

What is WinSCP?

It is award-winning SFTP client, SCP client, FTPS client and FTP client integrated into one software program for file transfer to FTP server or secure SFTP server. [More]

And it's free!

Donate

About donations

$9   $19   $49   $99

About donations

Recommend

WinSCP Privacy Policy

WinSCP License