Ssis 多表
我们正在寻找一种方法来压缩数百个表,并通过sftp将它们发送到另一台服务器。我们正在考虑使用SSI,但如果没有某种类型的附加组件,SSI将不会使用sftp。另一个可能更好的选择是什么 附加要求Ssis 多表,ssis,sftp,Ssis,Sftp,我们正在寻找一种方法来压缩数百个表,并通过sftp将它们发送到另一台服务器。我们正在考虑使用SSI,但如果没有某种类型的附加组件,SSI将不会使用sftp。另一个可能更好的选择是什么 附加要求 每个表应该有一个zip文件 表驱动方法将用于确定将传输哪些表。即,一个表将包含要传输的每个表的名称 我认为这两个要求在SSIS中很难实现。例如,进行压缩需要一个批处理脚本。然后我们将有一个批处理脚本和一些c#代码需要维护。也许还有另一个解决办法 假设性问题 这会比拥有数百个SSI包(每个包同时在不同的
- 每个表应该有一个zip文件
- 表驱动方法将用于确定将传输哪些表。即,一个表将包含要传输的每个表的名称李>
其思想是服务器将同时运行多个包,因为此方法一次只能运行一个convert、zip和transfer 这就是我如何使用SSIS完成这项工作的。我创建了一个可以在脚本任务中引用的C#DLL。我这样做是为了可以使用我的类库从其他应用程序中获取SFTP。因此,如果您不想使用SSI,您可以选择设置windows服务 首先,我创建对WinSCPNet.dll的引用,可在以下位置找到: 这是我创建的代码。它仍然是一个原型形式,您需要做一些事情,比如添加正确的错误处理/日志记录,我只是在使用Console.Writeline
public class Sftp
{
public static int ListFiles(string Password, string HostName, string UserName, string SshHostKeyFingerprint)
{
try
{
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = HostName,
UserName = UserName,
Password = Password,
SshHostKeyFingerprint = SshHostKeyFingerprint
};
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
RemoteDirectoryInfo directory = session.ListDirectory("/");
foreach (RemoteFileInfo fileInfo in directory.Files)
{
Console.WriteLine("{0} with size {1}, permissions {2} and last modification at {3}",
fileInfo.Name, fileInfo.Length, fileInfo.FilePermissions, fileInfo.LastWriteTime);
}
}
return 0;
}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e);
return 1;
}
}
public static int GetFiles(string Password, string HostName, string UserName, string SshHostKeyFingerprint)
{
try
{
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = HostName,
UserName = UserName,
Password = Password,
SshHostKeyFingerprint = SshHostKeyFingerprint
};
using (Session session = new Session())
{
// Connect
session.Open(sessionOptions);
// Download files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
TransferOperationResult transferResult;
transferResult = session.GetFiles("/home/user/*", "d:\\download\\", true, transferOptions);
// Throw on any error
transferResult.Check();
// Print results
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
Console.WriteLine("Download of {0} succeeded", transfer.FileName);
}
}
return 0;
}
catch (Exception e)
{
Console.WriteLine("Error: {0}", e);
return 1;
}
}
// Copy and pasted code shared with PutFile, refactor if making changes.
public static int PutFiles(string Password, string HostName, string UserName, string SshHostKeyFingerprint, string SourceFolder, string RemoteFolder, string FileMask, string WinScpExePath)
{
try
{
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = HostName,
UserName = UserName,
Password = Password,
SshHostKeyFingerprint = SshHostKeyFingerprint
};
using (Session session = new Session())
{
// Connect
session.ExecutablePath = WinScpExePath;
session.Open(sessionOptions);
// Upload files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
TransferOperationResult transferResult;
transferResult = session.PutFiles(SourceFolder + FileMask, RemoteFolder, false, transferOptions);
// Throw on any error
transferResult.Check();
// Print results
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
}
}
return 0;
}
catch (Exception e)
{
Console.WriteLine($"Error: {e}");
return 1;
}
}
// Copy and pasted code from PutFiles, refactor if making changes.
public static int PutFile(string Password, string HostName, string UserName, string SshHostKeyFingerprint, string InputFile, string RemoteFolder, string WinScpExePath)
{
try
{
// Setup session options
SessionOptions sessionOptions = new SessionOptions
{
Protocol = Protocol.Sftp,
HostName = HostName,
UserName = UserName,
Password = Password,
SshHostKeyFingerprint = SshHostKeyFingerprint
};
using (Session session = new Session())
{
// Connect
session.ExecutablePath = WinScpExePath;
session.Open(sessionOptions);
// Upload files
TransferOptions transferOptions = new TransferOptions();
transferOptions.TransferMode = TransferMode.Binary;
TransferOperationResult transferResult;
transferResult = session.PutFiles(InputFile, RemoteFolder, false, transferOptions);
// Throw on any error
transferResult.Check();
// Print results
foreach (TransferEventArgs transfer in transferResult.Transfers)
{
Console.WriteLine("Upload of {0} succeeded", transfer.FileName);
}
}
return 0;
}
catch (Exception e)
{
Console.WriteLine($"Error: {e}");
return 1;
}
}
}
我为SFTP编写了一个定制的c#脚本任务。大约有20-30行代码。我相信我使用了HttpRequest.Net类。@JoeC
HttpRequest
或任何其他标准的.Net类都不能进行SFTP。@JoeC是的,传输将需要使用sftpMy bad完成。我记不清了。我使用了WinScpNet。我们这里也使用WinSCP。这会在发送文件之前压缩文件吗?我们希望每个表有一个zip文件,这是严格意义上的SFTP部分。它不会写出或压缩表格。您可以查看ionic.zip->