SSIS 任务 - FTP 连接
SSIS Task - FTP Conecction
全部,
SSIS - 尝试使用可视化基本编程语言中的脚本任务建立 ftp 连接以将文件上传到 ftp 服务器,我遇到了 运行 问题。我在搜索中没有找到类似的东西,所以非常感谢你的帮助。
[连接管理器“FTP”]错误:请求的 FTP 操作发生错误。详细错误描述:220
控制通道需要 550 SSL/TLS
代码:
Public Sub Main()
'
' Add your code here
'
Try
Dim cm As ConnectionManager
cm = Dts.Connections("FTP")
'Set the properties like username & password
cm.Properties("ServerName").SetValue(cm, "ftps.example.com")
cm.Properties("ServerUserName").SetValue(cm, "username")
cm.Properties("ServerPassword").SetValue(cm, "password")
cm.Properties("ServerPort").SetValue(cm, "port")
cm.Properties("Timeout").SetValue(cm, "0") 'The 0 setting will make it not timeout
cm.Properties("ChunkSize").SetValue(cm, "1000") '1000 kb
cm.Properties("Retries").SetValue(cm, "1")
'create the FTP object that sends the files and pass it the connection created above.
Dim ftp As FtpClientConnection = New FtpClientConnection(cm.AcquireConnection(Nothing))
'Connects to the ftp server
ftp.Connect()
'Build a array of all the file names that is going to be FTP'ed (in this case only one file)
Dim files(0) As String
files(0) = "C:\ local path file"
'ftp the file
ftp.SendFiles(files, "/remote path", True, False) ' the True makes it overwrite existing file and False is saying that it is not transferring ASCII
ftp.Close()
Catch ex As Exception
Dts.TaskResult = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
End Try
……我终于解决了。我将语言脚本任务更改为 C#(它在 VB 中工作,您只需调整代码)并使用 this 评论中的代码。
注意:如果服务器位于 21 以外的端口上,您必须在远程路径中指定它。谢谢。
public void Main()
{
// TODO: Add your code here
FtpWebRequest request =
(FtpWebRequest)WebRequest.Create("ftp://ftps.example.com:port/remote/path/file.zip");
request.Credentials = new NetworkCredential("username", "password");
request.EnableSsl = true;
request.Method = WebRequestMethods.Ftp.UploadFile;
using (Stream fileStream = File.OpenRead(@"C:\local\path\file.zip"))
using (Stream ftpStream = request.GetRequestStream())
{
fileStream.CopyTo(ftpStream);
}
}
全部,
SSIS - 尝试使用可视化基本编程语言中的脚本任务建立 ftp 连接以将文件上传到 ftp 服务器,我遇到了 运行 问题。我在搜索中没有找到类似的东西,所以非常感谢你的帮助。
[连接管理器“FTP”]错误:请求的 FTP 操作发生错误。详细错误描述:220
控制通道需要 550 SSL/TLS
代码:
Public Sub Main()
'
' Add your code here
'
Try
Dim cm As ConnectionManager
cm = Dts.Connections("FTP")
'Set the properties like username & password
cm.Properties("ServerName").SetValue(cm, "ftps.example.com")
cm.Properties("ServerUserName").SetValue(cm, "username")
cm.Properties("ServerPassword").SetValue(cm, "password")
cm.Properties("ServerPort").SetValue(cm, "port")
cm.Properties("Timeout").SetValue(cm, "0") 'The 0 setting will make it not timeout
cm.Properties("ChunkSize").SetValue(cm, "1000") '1000 kb
cm.Properties("Retries").SetValue(cm, "1")
'create the FTP object that sends the files and pass it the connection created above.
Dim ftp As FtpClientConnection = New FtpClientConnection(cm.AcquireConnection(Nothing))
'Connects to the ftp server
ftp.Connect()
'Build a array of all the file names that is going to be FTP'ed (in this case only one file)
Dim files(0) As String
files(0) = "C:\ local path file"
'ftp the file
ftp.SendFiles(files, "/remote path", True, False) ' the True makes it overwrite existing file and False is saying that it is not transferring ASCII
ftp.Close()
Catch ex As Exception
Dts.TaskResult = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure
End Try
……我终于解决了。我将语言脚本任务更改为 C#(它在 VB 中工作,您只需调整代码)并使用 this 评论中的代码。
注意:如果服务器位于 21 以外的端口上,您必须在远程路径中指定它。谢谢。
public void Main()
{
// TODO: Add your code here
FtpWebRequest request =
(FtpWebRequest)WebRequest.Create("ftp://ftps.example.com:port/remote/path/file.zip");
request.Credentials = new NetworkCredential("username", "password");
request.EnableSsl = true;
request.Method = WebRequestMethods.Ftp.UploadFile;
using (Stream fileStream = File.OpenRead(@"C:\local\path\file.zip"))
using (Stream ftpStream = request.GetRequestStream())
{
fileStream.CopyTo(ftpStream);
}
}