WinSCP - 如何识别文件是否已成功传输

时间:2012-08-31 09:19:41

标签: scripting sftp winscp

我正在使用WinSCP通过SFTP自动上传文件。我已经打开了1级调试日志。是否可以找出文件是否已成功上传?谢谢。

日志文件的一部分:

. 2012-08-30 15:30:06.539 File: "C:\files\file_20120830.gpg"
. 2012-08-30 15:30:06.539 Copying "C:\files\file_20120830.gpg" to remote directory started.
. 2012-08-30 15:30:06.539 Binary transfer mode selected.
. 2012-08-30 15:30:06.539 Checking existence of file.
> 2012-08-30 15:30:06.539 Type: SSH_FXP_LSTAT, Size: 50, Number: 263
. 2012-08-30 15:30:06.539 Sent 54 bytes
. 2012-08-30 15:30:06.539 There are 0 bytes remaining in the send buffer
. 2012-08-30 15:30:06.539 Waiting for another 4 bytes
. 2012-08-30 15:30:06.555 Detected network event
. 2012-08-30 15:30:06.555 Received 33 bytes (0)
. 2012-08-30 15:30:06.555 Read 4 bytes (29 pending)
. 2012-08-30 15:30:06.555 Read 29 bytes (0 pending)
< 2012-08-30 15:30:06.555 Type: SSH_FXP_STATUS, Size: 29, Number: 263
< 2012-08-30 15:30:06.555 Status code: 2
. 2012-08-30 15:30:06.555 Checking existence of partially transfered file.
> 2012-08-30 15:30:06.555 Type: SSH_FXP_LSTAT, Size: 59, Number: 519
. 2012-08-30 15:30:06.555 Sent 63 bytes
. 2012-08-30 15:30:06.555 There are 0 bytes remaining in the send buffer
. 2012-08-30 15:30:06.555 Waiting for another 4 bytes
. 2012-08-30 15:30:06.570 Detected network event
. 2012-08-30 15:30:06.570 Received 33 bytes (0)
. 2012-08-30 15:30:06.570 Read 4 bytes (29 pending)
. 2012-08-30 15:30:06.570 Read 29 bytes (0 pending)
< 2012-08-30 15:30:06.570 Type: SSH_FXP_STATUS, Size: 29, Number: 519
< 2012-08-30 15:30:06.570 Status code: 2
. 2012-08-30 15:30:06.570 Opening remote file.
> 2012-08-30 15:30:06.570 Type: SSH_FXP_OPEN, Size: 75, Number: 771
. 2012-08-30 15:30:06.570 Sent 79 bytes
. 2012-08-30 15:30:06.570 There are 0 bytes remaining in the send buffer
. 2012-08-30 15:30:06.570 Waiting for another 4 bytes
. 2012-08-30 15:30:06.586 Detected network event
. 2012-08-30 15:30:06.586 Received 31 bytes (0)
. 2012-08-30 15:30:06.586 Read 4 bytes (27 pending)
. 2012-08-30 15:30:06.586 Read 27 bytes (0 pending)
< 2012-08-30 15:30:06.586 Type: SSH_FXP_HANDLE, Size: 27, Number: 771
. 2012-08-30 15:30:06.586 Write request offset: 0, len: 4096
> 2012-08-30 15:30:06.586 Type: SSH_FXP_WRITE, Size: 4135, Number: 1286
. 2012-08-30 15:30:06.586 Sent 4139 bytes
. 2012-08-30 15:30:06.586 There are 0 bytes remaining in the send buffer
. 2012-08-30 15:30:06.586 Write request offset: 4096, len: 4096
> 2012-08-30 15:30:06.586 Type: SSH_FXP_WRITE, Size: 4135, Number: 1542
. 2012-08-30 15:30:06.586 Sent 4139 bytes
. 2012-08-30 15:30:06.586 There are 0 bytes remaining in the send buffer
. 2012-08-30 15:30:06.586 Write request offset: 8192, len: 4096
> 2012-08-30 15:30:06.586 Type: SSH_FXP_WRITE, Size: 4135, Number: 1798
. 2012-08-30 15:30:06.586 Sent 4139 bytes
. 2012-08-30 15:30:06.586 There are 0 bytes remaining in the send buffer
. 2012-08-30 15:30:06.586 Write request offset: 12288, len: 4096
> 2012-08-30 15:30:06.586 Type: SSH_FXP_WRITE, Size: 4135, Number: 2054
. 2012-08-30 15:30:06.586 Sent 4139 bytes
. 2012-08-30 15:30:06.586 There are 0 bytes remaining in the send buffer
. 2012-08-30 15:30:06.586 Write request offset: 16384, len: 4096
> 2012-08-30 15:30:06.586 Type: SSH_FXP_WRITE, Size: 4135, Number: 2310
. 2012-08-30 15:30:06.586 Sent 4139 bytes
. 2012-08-30 15:30:06.586 There are 0 bytes remaining in the send buffer
. 2012-08-30 15:30:06.586 Write request offset: 20480, len: 4096
> 2012-08-30 15:30:06.586 Type: SSH_FXP_WRITE, Size: 4135, Number: 2566
. 2012-08-30 15:30:06.586 Sent 4139 bytes
. 2012-08-30 15:30:06.586 There are 0 bytes remaining in the send buffer
. 2012-08-30 15:30:06.586 Write request offset: 24576, len: 4096
> 2012-08-30 15:30:06.586 Type: SSH_FXP_WRITE, Size: 4135, Number: 2822
. 2012-08-30 15:30:06.602 Sent 4139 bytes
. 2012-08-30 15:30:06.602 There are 0 bytes remaining in the send buffer
. 2012-08-30 15:30:06.602 Write request offset: 28672, len: 98261
> 2012-08-30 15:30:06.602 Type: SSH_FXP_WRITE, Size: 98300, Number: 3078
. 2012-08-30 15:30:06.617 Sent 98304 bytes
. 2012-08-30 15:30:06.617 There are 33208 bytes remaining in the send buffer
. 2012-08-30 15:30:06.617 Detected network event
. 2012-08-30 15:30:06.617 Received 28 bytes (0)
. 2012-08-30 15:30:06.617 Read 4 bytes (24 pending)
. 2012-08-30 15:30:06.617 Read 24 bytes (0 pending)
< 2012-08-30 15:30:06.617 Type: SSH_FXP_STATUS, Size: 24, Number: 1286
< 2012-08-30 15:30:06.617 Status code: 0
. 2012-08-30 15:30:06.617 There are 33208 bytes remaining in the send buffer, need to send at least another 440 bytes
. 2012-08-30 15:30:06.633 Detected network event
. 2012-08-30 15:30:06.633 There are 33208 bytes remaining in the send buffer
. 2012-08-30 15:30:06.633 There are 33208 bytes remaining in the send buffer, need to send at least another 440 bytes
. 2012-08-30 15:30:06.633 Detected network event
. 2012-08-30 15:30:06.633 There are 33208 bytes remaining in the send buffer
. 2012-08-30 15:30:06.633 There are 33208 bytes remaining in the send buffer, need to send at least another 440 bytes
. 2012-08-30 15:30:06.633 Detected network event
. 2012-08-30 15:30:06.633 Received 28 bytes (0)
. 2012-08-30 15:30:06.633 Read 4 bytes (24 pending)
. 2012-08-30 15:30:06.633 Read 24 bytes (0 pending)
< 2012-08-30 15:30:06.633 Type: SSH_FXP_STATUS, Size: 24, Number: 1542
< 2012-08-30 15:30:06.633 Status code: 0

3 个答案:

答案 0 :(得分:2)

引用WinSCP常见问题How do I know that script completed successfully?

  

您可以通过WinSCP退出代码告诉脚本的结果。代码0表示成功,而1表示错误。有关更多详细信息,请参阅scripting文档。

     

批处理脚本(使用/script/command command-line switches指定)在发生任何错误后立即终止代码1。您可以使用option batch命令更改此内容。

     

要找出脚本失败的原因,请检查session log

     

有关示例,请参阅guide to transfer automationretrying s/connection attempt上的示例。

     

如果您需要更好地控制错误处理,请考虑使用WinSCP .NET assembly代替(例如来自PowerShell script)。

答案 1 :(得分:1)

WinSCP可以选择将您的所有操作记录到XML log。 然后,您可以分析日志以确切了解会话期间发生的事情。

答案 2 :(得分:1)

下面是用于完成从ftp服务器到本地目录的同步的批处理文件,删除本地端的任何更改。批处理文件还保存所有传输的 XML日志

@echo off
cd %programfiles(x86)%\winscp\
start /b winscp.exe /log="C:\Sync\logs\!M-!D-!Y@!T.xml" /xmlgroups /command "open   ftp://username:password@ftp.foo.com" "synchronize local -delete -criteria=size     ""C:\Users\jdoe\Documents\Synced Docs"" / 

您要玩的参数是“ winscp.exe /log="C:\Sync\logs!M-!D-!Y@!T.xml”/ xmlgroups