简体   繁体   English

使用功能app将文件从Sftp移到Azure容器

[英]Move the file from Sftp to the Azure container using function app

I was writing a C# program to move the file from Sftp to the Azure container. 我正在编写一个C#程序,将文件从Sftp移到Azure容器。 Using visual studio I'm able to move the file from sftp to container. 使用Visual Studio,我可以将文件从sftp移到容器。 I wanted to make it through Azure function app. 我想通过Azure功能应用程序做到这一点。 Below is the code i have written in visual studio. 下面是我在Visual Studio中编写的代码。 In azure function app i'm getting many error including reference not found. 在azure函数应用程序中,我遇到许多错误,包括找不到参考。 Could any one advise me how to make work this code in azure function app? 有人可以建议我如何在azure函数应用中使此代码生效吗?

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 谢谢

You need to make sure all your non-framework dependencies ( Rensi.SshNet , Newtonsoft.Json ) are included via project.json . 您需要确保通过project.json包括所有非框架依赖项( Rensi.SshNetNewtonsoft.Json )。 See this related issue on github . 请参阅github上的相关问题 And you may need to include framework dependencies (the ones starting with System ) via #r "System.Linq" style calls. 您可能需要通过#r "System.Linq"样式调用包括框架依赖关系(以System开头的依赖关系)。

Before do that you could refer to an introduction to Azure Functions to learn more about Azure function. 在此之前,您可以参考Azure函数简介以了解有关Azure函数的更多信息。

We also could create the Azure function Application with VS . 我们还可以使用VS创建Azure功能应用程序 You could follow this tutorial to do that. 您可以按照本教程进行操作。

In azure function app i'm getting many error including reference not found. 在azure函数应用程序中,我遇到许多错误,包括找不到参考。

If possible, a screenshot of exception will be more helpful. 如果可能的话,异常的屏幕快照会更有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM