Get files Based on date what you want (SFTP connection)

Advertisement

ebensalot
Joined:
Posts:
1
Location:
Phillipines

Get files Based on date what you want (SFTP connection)

Good day Winscp Supports,

I want to copy a file from the server based on date user inserted

this is the script I used but all files will get not the the date I input:

this is the .bat file to call the winscp script:


@echo off

:main
echo Inputdate(YYYYMMDD)
set /p car=
if %car% == 1 goto date

mkdir "C:\Documents and Settings\asd\Desktop\%car%"
WinSCP.com /script=sample.txt
pause


And this is the winscp script:

option batch abort
option confirm off


open sftp://username:password@Ip ADd -hostkey="ssh-rsa 2048 c5:89:02:bd:ce:66:ec:18:e2:10:b6:40:2f:81:a0:a6"


get -filemask="*>=%TIMESTAMP#yyyy-mm-dd%" /media/4B90C3C70BA785A7/melvin.luching C:\SMARTVISTA\%car%

exit

Reply with quote E-mail

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
28,659
Location:
Prague, Czechia

Re: Get files Based on date what you want (SFTP connection)

You have to use the car in your -filemask. And the car has to be in format YYYY-MM-DD, not YYYYMMDD:

get -filemask="*>=%car%" /media/4B90C3C70BA785A7/melvin.luching C:\SMARTVISTA\%car%

Reply with quote

Guest

Re: Get files Based on date what you want (SFTP connection)

martin wrote:

You have to use the car in your -filemask. And the car has to be in format YYYY-MM-DD, not YYYYMMDD:

get -filemask="*>=%car%" /media/4B90C3C70BA785A7/melvin.luching C:\SMARTVISTA\%car%

Hi Sir Martin.

How to get the files only that I inserted date. because this script give me a all files after the inserted date
eg: i want to get 05-30-2016 but the script was getting from 05-30-2016 up to date today.

Thanks,

Reply with quote

martin
Site Admin
martin avatar
Joined:
Posts:
28,659
Location:
Prague, Czechia

Re: Get files Based on date what you want (SFTP connection)

get -filemask="*>=%car%<=%car% 23:59:59" /media/4B90C3C70BA785A7/melvin.luching C:\SMARTVISTA\%car%[/quote]

Reply with quote

Guest

Re: Get files Based on date what you want (SFTP connection)

martin wrote:

get -filemask="*>=%car%<=%car% 23:59:59" /media/4B90C3C70BA785A7/melvin.luching C:\SMARTVISTA\%car%


Hi Sir,

I Cant copy the file inside the folder of the date I input this is the script I used:

get -filemask="*>=%car%<=%car% 23:59:59" /media/4B90C3C70BA785A7/melvin.luching/copy1tolocal/reports/%car% C:\SMARTVISTA\%car%\reports

the filename format of the folder is 03302016 but the date format need to Input in my script is YYYY-MM-DD format, when I try to change that to MMDDYYYY I can copy the folder but the file created in the input date didn't copy.

I uploaded the picture of the directory of my ftp server thanks,

Melvin.

winscp.jpg

Reply with quote

Advertisement

martin
Site Admin
martin avatar
Joined:
Posts:
28,659
Location:
Prague, Czechia

Re: Get files Based on date what you want (SFTP connection)

So just convert one format to the other.

Like:

echo Inputdate(YYYY-MM-DD)
set /p CAR=
set CAR_MMDDYYYY=%CAR:~5,2%%CAR:~8,2%%CAR:~0,4%

See https://ss64.com/nt/syntax-substring.html

Though this has no longer anything to do with WinSCP.

Reply with quote

Advertisement

You can post new topics in this forum