I was writing a C# program to move the file from Sftp to the Azure container. Using visual studio I'm able to move the file from sftp to container. I wanted to make it through Azure function app. Below is the code i have written in visual studio. In azure function app i'm getting many error including reference not found.
Could any one advise me how to make work this code in azure function app?
using System;
using System.Threading;
using System.IO;
using System.Configuration;
using Renci.SshNet;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
using Microsoft.WindowsAzure.Storage.Auth;
using Newtonsoft.Json;
using System.Linq;
using Microsoft.Win32;
using System.Xml;
using System.Collections.Generic;
public class CloudStorageAccount
{
const string host = "";
const string username = "";
const string password = "";
const string workingdirectory = "/home/Inbound/";
const int port = 22;
//Connection to the sftp
const string StorageAccountName = "";
const string StorageAccountKey = "";
StorageCredentials storageCredentials = new
StorageCredentials(StorageAccountName, StorageAccountKey);
CloudStorageAccount cloudStorageAccount = new
CloudStorageAccount(storageCredentials, useHttps: true);
CloudBlobClient blobClient = cloudStorageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("sample");
var blobs = container.ListBlobs();
using (var client = new SftpClient(host, port, username, password))
{
client.Connect();
client.ChangeDirectory(workingdirectory);
var listDirectory = client.ListDirectory(workingdirectory);
foreach (var fi in listDirectory)
{
if (fi.Name.Contains(".txt"))
{
string remoteFileName = fi.Name;
using (StreamReader file1 = new
StreamReader(client.OpenRead(source + remoteFileName)))
{
String oldContent = file1.ReadToEnd();
CloudBlockBlob blob = container.GetBlockBlobReference(remoteFileName);
blob.UploadText(oldContent);
}
}
}
}
}
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…