这章把脚本任务访问FTP的方法 全部给大家
如果对前面还有不了解的可以点击下面的目录进行学习。
至此 SSIS 学习之旅 到这里就结束了。希望对大家的学习和工作有所帮助吧。
第三章:SSIS 学习之旅 数据同步
#region 连接FTP服务器
/// <summary>
/// 连接FTP服务器
/// </summary>
/// <param name="FtpServerIP">FTP连接地址</param>
/// <param name="FtpRemotePath">指定FTP连接成功后的当前目录, 如果不指定即默认为根目录</param>
public string FTPHelper(string FtpServerIP, string FtpRemotePath)
{
string ftpURI = "ftp://" + FtpServerIP + "/" + FtpRemotePath + "/";
return ftpURI;
}
#endregion
#region 文件上传FTP服务器
/// <summary>
/// 上传
/// </summary>
/// <param name="FilePathPendingAndName">文件详细路径</param>
/// <param name="FTPUrl">FTPUrl</param>
/// <param name="FTP_UserName">用户名</param>
/// <param name="FTP_PWD">密码</param>
public void Upload(string FilePathPendingAndName, string FTPUrl, string FTP_UserName, string FTP_PWD)
{
FileInfo fileInf = new FileInfo(FilePathPendingAndName);
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri(FTPUrl + fileInf.Name));
reqFTP.Credentials = new NetworkCredential(FTP_UserName, FTP_PWD);
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
reqFTP.KeepAlive = false;
reqFTP.UseBinary = true;
reqFTP.ContentLength = fileInf.Length;
int buffLength = 2048;
byte[] buff = new byte[buffLength];
int contentLen;