使用功能app将文件从Sftp移到Azure容器 [英] Move the file from Sftp to the Azure container using function app

查看:76
本文介绍了使用功能app将文件从Sftp移到Azure容器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个C#程序,将文件从Sftp移到Azure容器.使用Visual Studio,我可以将文件从sftp移到容器.我想通过Azure功能应用程序做到这一点.下面是我在Visual Studio中编写的代码.在azure函数应用中,我遇到许多错误,包括找不到参考. 有人可以建议我如何在azure函数应用中使此代码生效吗?

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);

                    }
                }
            }
        }
}

谢谢

推荐答案

在此之前,您可以参考

Before do that you could refer to an introduction to Azure Functions to learn more about Azure function.

我们还可以使用以下方法创建 Azure函数应用程序VS .您可以按照教程进行操作

We also could create the Azure function Application with VS. You could follow this tutorial to do that.

在azure功能应用程序中,我遇到很多错误,包括找不到参考.

In azure function app i'm getting many error including reference not found.

如果可能的话,异常的屏幕快照会更有帮助.

If possible, a screenshot of exception will be more helpful.

这篇关于使用功能app将文件从Sftp移到Azure容器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆