You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

SSIS脚本任务建立FTP连接上传时报SSL/TLS要求错误如何解决

错误原因

[连接管理器“FTP”]错误:请求的FTP操作发生错误。详细错误描述:220
550 控制通道需要使用SSL/TLS

上述报错的核心原因是SSIS原生的FtpClientConnection类以及默认FTP连接管理器仅支持未加密的普通FTP协议,不支持目标服务器要求的FTPS(FTP over SSL/TLS)加密传输机制,无法自动完成TLS握手建立加密控制通道。

解决方案

推荐直接使用.NET框架内置的System.Net.FtpWebRequest类实现FTPS上传,该类支持自定义SSL/TLS加密配置,修改后的代码如下:

Imports System.Net
Imports System.IO

Public Sub Main()
    Try
        ' 配置FTPS连接参数
        Dim ftpServer As String = "ftps://ftps.example.com:端口/remote path/" ' 注意前缀加ftps://
        Dim userName As String = "username"
        Dim password As String = "password"
        Dim localFilePath As String = "C:\local path file"
        Dim fileName As String = Path.GetFileName(localFilePath)
        
        ' 创建FtpWebRequest对象
        Dim ftpRequest As FtpWebRequest = CType(WebRequest.Create(ftpServer & fileName), FtpWebRequest)
        ftpRequest.Method = WebRequestMethods.Ftp.UploadFile
        ftpRequest.Credentials = New NetworkCredential(userName, password)
        
        ' 启用SSL/TLS加密
        ftpRequest.EnableSsl = True
        ' 若服务器使用自签名证书,可临时添加以下代码跳过证书验证(生产环境不建议使用)
        ' ServicePointManager.ServerCertificateValidationCallback = Function(sender, certificate, chain, sslPolicyErrors) True
        
        ftpRequest.UseBinary = True ' 二进制传输,适配所有文件类型
        ftpRequest.Timeout = -1 ' 无超时
        
        ' 读取本地文件流上传
        Dim fileStream As FileStream = File.OpenRead(localFilePath)
        Dim ftpStream As Stream = ftpRequest.GetRequestStream()
        
        Dim buffer(1024 * 1000) As Byte ' 1000KB分片传输
        Dim bytesRead As Integer
        Do
            bytesRead = fileStream.Read(buffer, 0, buffer.Length)
            ftpStream.Write(buffer, 0, bytesRead)
        Loop While bytesRead > 0
        
        ' 释放资源
        ftpStream.Close()
        fileStream.Close()
        
        ' 获取上传响应
        Dim response As FtpWebResponse = CType(ftpRequest.GetResponse(), FtpWebResponse)
        response.Close()
        
        Dts.TaskResult = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success
    Catch ex As Exception
        ' 可自行添加日志输出异常信息方便排查
        Dts.TaskResult = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
    End Try
End Sub

注意事项

  • 需确认服务器使用的FTPS类型:显式FTPS默认端口为21,隐式FTPS默认端口为990,根据实际情况修改连接地址中的端口配置
  • 生产环境不要跳过证书验证,避免传输安全风险
  • 需要在脚本任务的引用中添加System.Net、System.IO命名空间

内容的提问来源于stack exchange,提问作者Fido

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 07:45:04