Post a reply

Add an Attachment

If you do not want to add an Attachment to your Post, please leave the Fields blank.

(maximum 10 MB; please compress large files; only common media, archive, text and programming file formats are allowed)


Topic review


Where id i say
"WinSCP not liking a slash"

This is not about "WinSCP not liking a slash". On Windows, you cannot use a slash in a filename.

Ok so it was just the format of the string in the date - it doesn't like the "/" characters in the filename.

Changed it to
$DateTime = Get-Date -format dd-MM-yyyy

and then
$session.SessionLogPath = "X:\Logs\Daily Download $DateTime.log"
works just fine

Logging to a file with today's date and time


I'm trying to to write output to a logfile with today's date and time in the name of the file, so i'd have a new file for each day's transfer activities.

Logging works fine if i don't insert a date/time variable into the filename like so:

   $session = New-Object WinSCP.Session

   $session.SessionLogPath = "X:\Logs\TransferLog.log"

But if i try and enter the date/time variable - it tries but then fails:

$DateTime = Get-Date -format yyyy/MM/dd

$session = New-Object WinSCP.Session
$session.SessionLogPath = "X:\Logs\TransferLog-$DateTime.log"

Even though it seems to accept the variable in the filename it can't find it or create it - but as I've mentioned, works fine without the variable so the same file location.
Can't open log file 'X:\Logs\TransferLog-2018/09/25.log'.

System Error.  Code: 2.
The system cannot find the file specified"

i know its not permissions since it can write to the same location without the variable inserted.

Any ideas?