我在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? 谢谢你的任何建议!
答案 0 :(得分:0)
假设sftp客户端可以通过http检索数据,我的猜测是blob存储在未配置为允许公共访问的容器中。如果您运行Fiddler运行代码,我猜你在sftp尝试检索文件时会看到服务器身份验证错误。如果是这种情况,那么您可以提供SAS令牌以及允许访问该文件的URL,也可以将容器配置为允许公共访问。有关更多信息,请参阅以下文章: