Jacob Lynn
Jacob Lynn

Reputation: 31

Timestamp and Increased levels of verbose logging using PSFTP

I am needing to add verbose logging to an FTP to another system as they claim they are not always receiving a file sent.

I am calling psftp.exe using a script and trying the -v option for verbose logging which works, I also want to add a timestamp to either the log file or inside the log.

I also noticed using -v 3 and -v 4 reveals more detailed logging. I wish to output this to a file.

Here is my putty call:

\\myserver\mytable\psftp.exe mylogin@myipaddress -pw mypassword -b C:\Users\pervasive\Desktop\mytable\mysftpscript.sftp  -v 2> \\myserver\mytable\mylog.txt

Upvotes: 1

Views: 4197

Answers (3)

JMGregory
JMGregory

Reputation: 1

While it will not give the time per transaction is it possible to have your psftp command in a bat file between two sets of date and time commands. This would at least frame the start and end of the psftp run.

date /t > \\myserver\mytable\mylog.txt
time /t >> \\myserver\mytable\mylog.txt
\\myserver\mytable\psftp.exe mylogin@myipaddress -pw mypassword -b C:\Users\pervasive\Desktop\mytable\mysftpscript.sftp  -v >> \\myserver\mytable\mylog.txt 2>&1
date /t >> \\myserver\mytable\mylog.txt
time /t >> \\myserver\mytable\mylog.txt

To get per transaction time logging you could run Windows commands from the sftp batch/script C:\Users\pervasive\Desktop\mytable\mysftpscript.sftp using the ! command at the key points you need the time recording.

!time /t
mput somefiles
!time /t

EDIT: Just tested the time command and not good. All the times hit the top of the output with the psftp verbose logging below so is not meaningful.

18/12/2020 
12:07
12:07
12:07
12:07
Connected to x.x.x.x
Remote working directory is /
New local directory is C:\_sftp\snd
Remote directory is now /remote/collect
Listing directory /remote/collect

Upvotes: 0

Jacob Lynn
Jacob Lynn

Reputation: 31

I wish I could vote for your answer but i still do not have the rep.

dir >> a.txt 2>&1

This does put them in one! The only draw back is it appends stderr to the end instead of putting it in the middle like it would be for a -v. It is the best solution I have found so far but still a little less than what my client wishes to see. Timestamps would also be nice but I added a time stamp at the beginning and end to encapsulate the process.

Upvotes: -1

Martin Prikryl
Martin Prikryl

Reputation: 202534

To log a complete verbose (-v) output of psftp to a file use:

psftp [email protected] -pw password -v > psftp.log 2>&1

See also Redirect Windows cmd stdout and stderr to a single file.


There's no way to make psftp produce timestamps.


Note that there are no verbosity levels in psftp. There's no -v 3 or -v 4.

Upvotes: 1

Related Questions