Thank you Dulio, is there any github or repo where I can pick up the code. I have copy+paste the code in that post and I get an error when connecting to FTP. I have also purchased your book with Stefano Demiliani but I cant make it work.
Here are the details of the error I get with the code in that post:
I am trying to upload a file into SFTP using Renci.SshNet within an Azure Function (find at the bottom).
I get a error when this line is executed: client.Connect();
Error is:
"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."
My user/password/ip/port are correct (I have checked it with Filezilla) Do you know what could be happening?
private static async Task<string> UploadFileToSFTP(Uri uri, string sourceFileName, ILogger log )
{
string storageAccountContainer = "csvfiles4magento";
string storageConnectionString = BLOBStorageConnectionString;
string sourceFileAbsolutePath = uri.ToString();
//SFTP Parameters (read it from configurations or Azure KeyVault)
string sftpAddress = "address";
string sftpPort = "port";
string sftpUsername = "username";
string sftpPassword = "password";
string sftpPath = "var";
string targetFileName = sourceFileName;
var memoryStream = new MemoryStream();
CloudStorageAccount storageAccount;
if (CloudStorageAccount.TryParse(storageConnectionString, out storageAccount))
{
CloudBlobClient cloudBlobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer cloudBlobContainer =
cloudBlobClient.GetContainerReference(storageAccountContainer);
CloudBlockBlob cloudBlockBlobToTransfer =
cloudBlobContainer.GetBlockBlobReference(new CloudBlockBlob(uri).Name);
await cloudBlockBlobToTransfer.DownloadToStreamAsync(memoryStream);
}
var methods = new List<AuthenticationMethod>();
methods.Add(new PasswordAuthenticationMethod(sftpUsername, sftpPassword));
//Connects to the SFTP Server and uploads the file
Renci.SshNet.ConnectionInfo con = new Renci.SshNet.ConnectionInfo(sftpAddress, sftpPort, new PasswordAuthenticationMethod(sftpUsername, sftpPassword));
using (var client = new SftpClient(con))
{
client.Connect();
client.UploadFile(memoryStream, $"/{sftpPath}/{targetFileName}");
client.Disconnect();
return targetFileName;
}
}]
Thank you