1

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
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Jacob Lynn
  • 31
  • 1
  • 9

3 Answers3

1

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

psftp user@example.com -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.

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
0

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
JMGregory
  • 1
  • 1
  • Issue may be if you need to the second logging this will not be effective as it is only to the minute. The link at the end has an answer to get to fraction of a second but I've not tested in a sftp batch file with the ! command. https://stackoverflow.com/questions/4248220/how-can-i-retrieve-the-seconds-part-of-time-in-cmd – JMGregory Dec 18 '20 at 11:44
  • Yes, I have left the company but as you can see in my response last year I was able to encapsulate timestamps before and after. You can write a batch file to write a timestamp and then edit that log file with the rest of your logging. That way the timestamps are written just prior as well. This worked well for the company and has been used unedited for the past year solving the business dispute. – Jacob Lynn Apr 12 '21 at 11:15
-1

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.

Jacob Lynn
  • 31
  • 1
  • 9