Link to home
Start Free TrialLog in
Avatar of ammartahir1978
ammartahir1978Flag for United Kingdom of Great Britain and Northern Ireland

asked on

how to pick only current date files from a ftp

Hi All,

I have a folder on ftp where all the files sit i just want to pick all the today's dated files.

Currently i am using this
open 10.10.34.5
userid
password
lcd D:\LABELS\ChessODBCFiles\BedfordSO

cd chess_new/bedford

binary
mget "A20161031*.*"


disconnect
quit

Open in new window


now you can see i have to change mget A20161031*.* to todays date which is A20161103*.*, i have to do this everytime how can i change it so that system automatically pick current dates files?

(edit: replaced userid and passwrod with generics)
Avatar of oBdA
oBdA

Don't know what you're using to run the ftp script, but this creates the script dynamically:
$TimeStamp = Get-Date -Format 'yyyyMMdd'
$mgetPattern = "A$($TimeStamp)*.*"

$FtpFile = Join-Path -Path $ENV:Temp -ChildPath "ChessODBCFiles.ftp"

@"
open 10.10.34.5
userid
password
lcd D:\LABELS\ChessODBCFiles\BedfordSO

cd chess_new/bedford

binary
mget "$($mgetPattern)"


disconnect
quit
"@ | Set-Content -Path $FtpFile

& ftp.exe -s:$FtpFile

Open in new window

Avatar of ammartahir1978

ASKER

Hi oBda,

I have this simple txt file which i run via schedule job.

so how do i run your script?
A text file doesn't execute itself. Are you using the Windows default ftp.exe, or which application (with which arguments) are you currently using to run the ftp script you posted?
this is how i run it

ftp -i -s:"D:\LABELS\ChessODBCFiles\FtpPickSO.txt"
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

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
Thanks odBa where does it save the log file and whats the name?
Excellent thank you so much
As defined in line 3.
hi oBda,

the script is not working i just changed the location to put files in.

can you check please.

$TimeStamp = Get-Date -Format 'yyyyMMdd'
$mgetPattern = "A$($TimeStamp)*.*"
$LogFile = 'C:\Users\atahir\Documents\FtpPickSO.log'

$FtpFile = Join-Path -Path $ENV:Temp -ChildPath 'ChessODBCFiles.ftp'

@"
open 10.10.34.5
ediftp
shelbyv1lle
lcd C:\Users\atahir\Documents\SALES_FILES

cd chess_new/bedford

binary
mget "$($mgetPattern)"


disconnect
quit
"@ | Set-Content -Path $FtpFile

& ftp.exe -i -s:$FtpFile 2>&1 | Set-Content -Path $LogFile

Open in new window

Regards,

Am
What is not working? The scheduled instance or the script in general?
What does the log file say?
What happens if you open a PS console, "cd" into the folder where the .ps1 file is stored, and run it manually from there?
this is what i get when i run it manually
error-powershell.PNG
Well, then the path to the ps1 file is obviously incorrect.
You need to fix the path inside the single quotes.
got it thank you stupid of me :) sorry to bother you
No problem. Sometimes things are just too obvious.