在CentOS上的Bamboo中的.Net Core SFTP集成测试

问题描述

我正在为SFTP代码编写集成测试,因此我的测试使用SFTP服务器库来启动SFTP服务器,以监听每个测试用例的随机端口。在Mac上的Visual Studio 2019上使用.Net Core,我的测试全部成功。当我在其代理运行CentOS的Bamboo构建服务器上运行时,出现以下错误

05:01:09.4224  ERROR Failed to connect to localhost System.Net.sockets.socketException (111): Connection refused
15-Aug-2020 05:01:10        at Renci.SshNet.Abstractions.socketAbstraction.Connect(IPEndPoint remoteEndpoint,TimeSpan connectTimeout)
15-Aug-2020 05:01:10        at Renci.SshNet.Session.socketConnect(String host,Int32 port)
15-Aug-2020 05:01:10        at Renci.SshNet.Session.Connect()
15-Aug-2020 05:01:10        at Renci.SshNet.BaseClient.CreateAndConnectSession()
15-Aug-2020 05:01:10        at Renci.SshNet.BaseClient.Connect()

日志表明SFTP服务器正在启动并正确绑定到随机端口,因此我不确定为什么到localhost的出站连接会失败。

解决方法

localhost无效,但是127.0.0.1有效。显然,构建代理程序没有配置localhost名称。