使用 PSFTP 的时间戳和增加的详细日志记录级别

Timestamp and Increased levels of verbose logging using PSFTP

我需要向 FTP 添加详细日志记录到另一个系统,因为他们声称他们并不总是收到发送的文件。

我正在使用脚本调用 psftp.exe 并尝试使用 -v 选项进行详细日志记录,我还想在日志文件或日志中添加时间戳。

我还注意到使用 -v 3-v 4 可以显示更详细的日志记录。我希望将其输出到文件中。

这是我的 putty 调用:

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

要将 psftp 的完整详细 (-v) 输出记录到文件中,请使用:

psftp user@example.com -pw password -v > psftp.log 2>&1

另见 Redirect Windows cmd stdout and stderr to a single file


无法使 psftp 生成时间戳。


请注意 psftp 中没有冗长级别。没有 -v 3-v 4.

我希望我能投票给你的答案,但我仍然没有代表。

目录 >> a.txt 2>&1

这确实把它们合二为一了!唯一的缺点是它将 stderr 附加到末尾,而不是像 -v 那样将其放在中间。这是迄今为止我找到的最好的解决方案,但仍然比我的客户希望看到的要少一些。时间戳也很好,但我在开始和结束时添加了一个时间戳来封装这个过程。

虽然它不会给出每个事务的时间,但是否可以将 psftp 命令放在两组日期和时间命令之间的 bat 文件中。这至少会构成 psftp 运行.

的开始和结束
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

要获取每个事务时间的日志记录,您可以从 sftp batch/script C:\Users\pervasive\Desktop\mytable\mysftpscript.sftp 使用 !命令在你需要时间记录的关键点。

!time /t
mput somefiles
!time /t

编辑:刚刚测试了时间命令,但效果不佳。所有时间都在输出的顶部使用下面的 psftp 详细日志记录,所以没有意义。

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