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

标签 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

最佳答案

引用 WinSCP FAQ How do I know that script completed successfully? :

You can tell the result of script by WinSCP exit code. Code 0 indicates success, while 1 indicates an error. For more details refer to scripting documentation.

Batch script (specified using /script or /command command-line switches) terminates with code 1 immediately once any error occurs. You can change this using option batch command.

To find out why the script failed, inspect session log.

For an example see:

If you need a better control of error handling, consider using WinSCP .NET assembly instead (e.g. from a PowerShell script).

关于scripting - WinSCP - 如何识别文件是否传输成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12212411/

相关文章:

shell - 如何在不替换当前 shell 的情况下重新加载 ZSH 配置文件?

java - JSch中如何设置文件类型和文件传输模式?

excel - 使用VBA运行WinSCP脚本

c# - 文件传输详细信息持续绑定(bind),直到使用 WPF 在窗口中传输文件

shell - BASH:有没有办法在不活动期间自动将最近的行保存到我的 bash 历史记录中?

javascript - 从脚本调用 .js 文件中的函数

c# - 有没有办法将 VS 与只能通过 sftp 访问的远程站点一起使用?

c# - 使用 WinSCP .NET 程序集从 FTP 服务器下载除特定文件夹之外的所有文件

linux - 比较linux(bash)中的两个平面文件,取出缺少的内容并将其放入第一个文件中?

css - 一段时间后代码恢复到原始主题