Reputation: 2860
here is my script:
$Path = "G:\FTP\APX\APXDropoff\Pay"
$Archive = "G:\FTP\APX\APXDropoff\Pay\Archive"
#$BankOfTulsa = "H:\Documentation\Projects\PJ\BankOfTulsa"
#$compareDate = (Get-Date).AddDays(-1)
$LastFile = Get-ChildItem $Path -Recurse | Where{$_.Name -Match "^CPdb(\d{6})(\d{8}).txt"}; $LastFile
CP $LastFile $Archive
#Call WinSCP Navigate to Incoming\Temp folder for test.
# & 'C:\Program Files (x86)\WinSCP\WinSCP.com' /command "option batch abort" "option confirm off" "open sftp:BankOfTulsa/" "put $LastFile /incoming/arp/"
So here's my issue. I am using reg ex to find the file the CP moves it just fine but when I go to upload to winSCP it says the file doesn't exist.
And it calls it by name, so the variable is there...
Authenticating with pre-entered password.
Authenticated.
Starting the session...
Reading remote directory...
Session started.
Active session: [1] BankOfAmerica
File or folder 'CPdb08131408252014.TXT' does not exist.
System Error. Code: 2.
The system cannot find the file specified
(A)bort, (R)etry, (S)kip, Ski(p) all: Abort
Please help!!
Upvotes: 0
Views: 554
Reputation: 46700
I would think that your issue would lie in that $LastFile
does not contain the full path of the file you are trying to upload. I would suggest you use the .FullName
property of $LastFile
since you have that from the Get-ChildItem
cmdlet.
"put $($LastFile.FullName) /incoming/arp/"
Also please refrain from using aliases where you can as some people might not know that CP
is an alias for Copy-Item
Afterthought
$lastFile
has the potential to match more that one file. If that is the case it would make a mess of the rest of the script potentially.
From your comment you can do the following:
Get-ChildItem $Path -Recurse | Where{$_.Name -Match "^CPdb(\d{6})(\d{8}).txt"} |
Sort-Object LastWriteTime -Descending | Select-Object -First 1
Upvotes: 1