将文件从 Azure 存储 Blob 传输到 SFTP 时遇到问题
Trouble transferring files from Azure Storage Blob to SFTP
我在 Azure 存储中创建了一个 xml(例如)并想将其直接上传到 SFTP 服务器。
string name = DateTime.Now.ToString("yyyyMMddhhmmss") + ".xml";
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container.
CloudBlobContainer container = blobClient.GetContainerReference("xxxxxxxxxxxx");
// Create the container if it doesn't already exist.
container.CreateIfNotExists();
//Create reference to a Blob that May or Maynot exist under the container
CloudBlockBlob blockBlob = container.GetBlockBlobReference(name);
// Create or overwrite the "something.xml" blob with contents from a string
string xml = "some xml";
blockBlob.UploadTextAsync(xml);
//Upload file to the sftp server
string fpath = "https://someazureserver.blob.core.windows.net/xxxxxxxxx/" + name;
sftp.Connect();
try
{
string INVENTORY = "xxxx/xxxx/xxxx"; //the file path in sftp
sftp.Put(fpath, INVENTORY);
}
finally { sftp.Close(); }
我尝试填写该 blob 的 url 的文件路径,但没有成功。我在网上搜索过,但没有找到任何关于 blob 文件路径的信息。还有另一种方法可以将文件从 azure 传输到 sftp 吗?
感谢您的任何建议!
假设 sftp 客户端可以通过 http 检索数据,我的猜测是 blob 存储在未配置为允许 public 访问的容器中。如果您 运行 使用 Fiddler 运行ning 的代码,我猜您会在 sftp 尝试检索文件时看到服务器身份验证错误。如果是这种情况,那么您可以提供一个 SAS 令牌以及允许访问该文件的 URL,或者您可以将容器配置为允许 public 访问。有关详细信息,请参阅以下文章:
我在 Azure 存储中创建了一个 xml(例如)并想将其直接上传到 SFTP 服务器。
string name = DateTime.Now.ToString("yyyyMMddhhmmss") + ".xml";
// Retrieve storage account from connection string.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
// Create the blob client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container.
CloudBlobContainer container = blobClient.GetContainerReference("xxxxxxxxxxxx");
// Create the container if it doesn't already exist.
container.CreateIfNotExists();
//Create reference to a Blob that May or Maynot exist under the container
CloudBlockBlob blockBlob = container.GetBlockBlobReference(name);
// Create or overwrite the "something.xml" blob with contents from a string
string xml = "some xml";
blockBlob.UploadTextAsync(xml);
//Upload file to the sftp server
string fpath = "https://someazureserver.blob.core.windows.net/xxxxxxxxx/" + name;
sftp.Connect();
try
{
string INVENTORY = "xxxx/xxxx/xxxx"; //the file path in sftp
sftp.Put(fpath, INVENTORY);
}
finally { sftp.Close(); }
我尝试填写该 blob 的 url 的文件路径,但没有成功。我在网上搜索过,但没有找到任何关于 blob 文件路径的信息。还有另一种方法可以将文件从 azure 传输到 sftp 吗? 感谢您的任何建议!
假设 sftp 客户端可以通过 http 检索数据,我的猜测是 blob 存储在未配置为允许 public 访问的容器中。如果您 运行 使用 Fiddler 运行ning 的代码,我猜您会在 sftp 尝试检索文件时看到服务器身份验证错误。如果是这种情况,那么您可以提供一个 SAS 令牌以及允许访问该文件的 URL,或者您可以将容器配置为允许 public 访问。有关详细信息,请参阅以下文章: