Hi All,
I create a ETL package to download data from SFTP server to Azure blob and load that file into a data warehouse. To complete this task i create a C# script task with SSH.net DLL file. when i run this application from my local machine its work fine. But when i deploy my ETL package into Azure integration service the code not working.
Every time i run from Azure integration service i m getting below error .
"Script Task:Error: 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 Renci.SshNet.Abstractions.SocketAbstraction.Connect(IPEndPoint remoteEndpoint, TimeSpan connectTimeout)
at Renci.SshNet.Session.SocketConnect(String host, Int32 port)
at Renci.SshNet.Session.Connect()
at Renci.SshNet.BaseClient.Connect()
at ST_c843d17ae6354854b7e946cb80e158c9.ScriptMain.Main()"
Azure support team inform me the relation between azure and SFTP have no issue the issue is in my code. But i m unable to find any issue in my code. below is my code
try
{
String Host = sftp address;
int Port = 22;
string DownloadDirectory = download folder;
if (!Directory.Exists(DownloadDirectory))
{
System.IO.Directory.CreateDirectory(DownloadDirectory);
}
String Username = username;
String Password = password;
string remoteDirectory = sftp folder path;
using (var sftp = new SftpClient(Host, Port, Username, Password))
{
sftp.Connect();
var files = sftp.ListDirectory(remoteDirectory);
foreach (var file in files)
{
string remoteFileName = file.Name;
if (File.Exists(DownloadDirectory + remoteFileName))
{
File.Delete(DownloadDirectory + remoteFileName);
}
using (Stream file1 = File.OpenWrite(DownloadDirectory + remoteFileName))
{
sftp.DownloadFile(remoteDirectory + remoteFileName, file1);
}
}
sftp.Disconnect();
}
}
catch (Exception ex)
{
Console.Write(ex.Message);
}
Thanks for your help. I'm not sure if i put correct tag or not.
Md. Muzahid Sarker