我尝试使用Renci.SshNet将生成的word文档上传到SFTP服务器:
if (protocol == "SFTP")
{
if (connectorSettings.DebugMode) properties.AddInfoMessage(_actionName + " " + "File Transfer via SFTP Protocol" + ".");
//SFTP
using (var sftpClient = new SftpClient(host, port, username, password))
{
//Connect clients to server
sftpClient.Connect();
if (connectorSettings.DebugMode) properties.AddInfoMessage(_actionName + " " + "Connected to " + host + ".");
try
{
//Create remote directory
if (createDirectory && !sftpClient.Exists(directory))
{
if (connectorSettings.DebugMode) properties.AddInfoMessage(_actionName + " " + "Directory Creation Start: " + directory + ".");
sftpClient.CreateDirectory(directory);
if (connectorSettings.DebugMode) properties.AddInfoMessage(_actionName + " Directory Creation Success");
}
sftpClient.ChangeDirectory(directory);
if (connectorSettings.DebugMode) properties.AddInfoMessage(_actionName + " " + "Destination directory: " + directory + ".");
using (var docStream = properties.GetDocumentStream(doc))
{
if (connectorSettings.DebugMode) properties.AddInfoMessage(_actionName + " " + "File Upload Start: " + doc.DisplayName + doc.Extension + ".");
sftpClient.BufferSize = 4 * 1024; // bypass Payload error large files
sftpClient.UploadFile(docStream, doc.DisplayName + doc.Extension);
}
if (connectorSettings.DebugMode) properties.AddInfoMessage(_actionName + " " + "Upload " + doc.DisplayName + doc.Extension + " " + " Completed.");
}
finally
{
sftpClient.Disconnect();
if (connectorSettings.DebugMode) properties.AddInfoMessage(_actionName + " " + "Disconnect from " + host + ".");
}
}
现在,这段代码可以与我一直在使用的所有客户端连接到他们的服务器并逐个上传多个文件。然而,昨天有一个新客户我得到了这个奇怪的问题:
我可以通过本地代码(本地应用程序)将多个文档成功连接并上传到他们的服务器。但是当我将Web应用程序发布到Azure时,我只能在前1分钟内连接并上传多个文档,之后我被阻止了1小时间隔而我的应用程序无法再连接,因此代码在sftpClient.Connect失败了();给我这个例外错误:
Error: System.Net.Sockets.SocketException (0x80004005): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond ....
at System.Net.Sockets.Socket.EndConnect(IAsyncResult asyncResult)
at Renci.SshNet.Session.SocketConnect(String host, Int32 port)
at Renci.SshNet.Session.Connect()
at Renci.SshNet.BaseClient.Connect()
at FileTransferActionProvider.FileTransferAction.Run(ActionProperties properties)
客户端使用的服务器是Bitvise SSH Server。阅读他们的文档我发现了这个:
“Bitvise SSH服务器试图阻止攻击者的另一种方式是通过自动阻止最近发起多次失败登录尝试的IP地址。在默认设置中,SSH服务器将阻止1小时在5分钟内启动20次以上失败登录尝试的IP地址。“
这很奇怪,因为我的应用程序已经成功登录,在前几次尝试上传文件时成功登录。我使用(Renci.ssh)或与Bitvise SSH服务器有什么关系的库有什么问题吗?
请帮忙。感谢