Link to home
Start Free TrialLog in
Avatar of Arikkan
ArikkanFlag for United States of America

asked on

Download a File for COREFTP using Command line and WILDCARDs in source Filename

Hi,

I want to download a file on COREFTP using the command line and I am trying to use the following command and it works perfectly fine when I use the Wildcards * or ?.

How can I use specific WILDCARDS as [0-9] or [00-31] or [0-1]{2} ?
See below what I am trying to do (File with a Date appended mmddyyyy format)

This command does not work.
C:\Program Files\CoreFTP>coreftp.exe -delsrc -nocase -s -O -site DailyFTPProfile -d /FileLocationOnFTP/Daily_[01-12][01-31][19-20][0-9][0-9].txt -p C:\DOWNLOADS\ -FN Daily.txt -log C:\LOGS\Log.txt  -output C:\OUTPUT\output.txt  -exit


This command works:
C:\Program Files\CoreFTP>coreftp.exe -delsrc -nocase -s -O -site DailyFTPProfile -d /FileLocationOnFTP/Daily_????????.txt -p C:\DOWNLOADS\ -FN Daily.txt -log C:\LOGS\Log.txt  -output C:\OUTPUT\output.txt  -exit


Any ideas?
Avatar of NVIT
NVIT
Flag of United States of America image

If you need to get the current date, try this in a .bat or .cmd file:

for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do set CurDate=%%j%%k%%l

coreftp.exe -delsrc -nocase -s -O -site DailyFTPProfile -d /FileLocationOnFTP/Daily_%CurDate%.txt -p C:\DOWNLOADS\ -FN Daily.txt -log C:\LOGS\Log.txt  -output C:\OUTPUT\output.txt  -exit

Open in new window

Avatar of Arikkan

ASKER

Thanks for your quick reply.  :-)
But the date on remote file might not be current date.

The file format is:
DAILY__mmddyyyy.txt

I am just trying to add a wildcard to validate the date on file and pick the correct file as there might be other files on the folder like:

DAILY__mmddyyyyIgnoreMe.txt
DAILY__mmyyyy.txt
DAILY__somenameABCD.txt
DAILY__yyyy.txt
DAILY__14442015.txt  -->Wrong Date
DAILY__mmddyyyyIgnoreMe.txt
DAILY__mmyyyy.txt
DAILY__somenameABCD.txt
DAILY__yyyy.txt

Are these correct files?
Avatar of Arikkan

ASKER

Yes. They might have names like these.

I just want the file with

DAILY__mmddyyyy.txt

to be picked
Avatar of Bill Prew
Bill Prew

Is COREFTP the only possible FTP client you can use?

~bp
I think you have a couple of options.

1. [b]Use a different FTP client[/b]

You may be able to find a different FTP client that allows REGEX patterns to be specified for the FTP get files command.  The only one I know of that I think this supports (I've never actually used it) is WGET, but perhaps there are others.  One of my favorite tools for scripted FTP is NCFTPGET, but it does not support REGEX.

2. [b]Filter a list of files locally[/b]

The other approach I can see is a multistep process.  You could first do an FTP command to get a list of all the files on the server that match your basic "????????" pattern, and then on the local PC use scripting to select by REGEX the desired files from that list.  Then take that list of matching files and use it to drive one or more FTP gets from the remote server.

~bp
Avatar of Arikkan

ASKER

Yes. I can use only COREFTP in our environment as it is already deployed at client side.

Then, I have to go with OPTION2: Filter a list of files locally.......

I can use a batch file to call COREFTP, so I need to do the following:

1. Use Command to get list of files on FTP for COREFTP
2. Get the correct file using scripting on local PC --> Do you know how I should do this?
3. Call COREFTP and download the selected file.
I am just trying to add a wildcard to validate the date on file and pick the correct file as there might be other files on the folder like:

DAILY__mmddyyyyIgnoreMe.txt
DAILY__mmyyyy.txt
DAILY__somenameABCD.txt
DAILY__yyyy.txt
DAILY__14442015.txt  -->Wrong Date
So you want all valid dates, right?

~bp
Here's an example command you could use in batch to filter out just files you want.

findstr -i -r -c:"daily_[01][0-9][0-3][0-9][12][901][0-9][0-9]\.txt" in.txt > out.txt

Open in new window

~bp
Avatar of Arikkan

ASKER

Thank you. I will try it and let you know. :-)
Avatar of Arikkan

ASKER

1. Use Command to get list of files on FTP for COREFTP  --> Cant seem to find this. Probably CoreFTP does not support it......
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