如何使用 Powershell 从 Azure 存储下载 blob 文件并将其保存到 FTP 服务器?
How to download a blob file from Azure Storage and save it to an FTP server using Powershell?
我正在尝试访问 PowerShell 中的 blob 文件并想将其直接保存到 FTP 服务器。如何才能做到这一点?这可以通过 blob 文件 URL 完成吗?或者我能以某种方式在 Powershell 内存中创建文件,然后使用 $webclient.UploadFile 将其保存到 FTP 文件夹吗?
与同一个下载相关的另一个问题是,有没有办法只复制文件而不是复制子目录?例如,我有一个像这样的 blob 文件:dataload/files/my_blob_file。当我使用命令 Get-AzureStorageBlobContent -Destination $destination_path 时,它将文件保存在相同的子文件夹结构中,但我可以改用自定义路径或删除子文件夹并将其另存为 c:\myfolder\my_blob_file c:\myfolder\dataload\files\my_blob_file?我想在上面的 FTP 服务器中完成此操作。
I am trying to access a blob file in PowerShell and want to save it directly to an FTP server.
如果您的 FTP 服务器是基于 Windows 的,那么您可以只 运行 FTP 服务器上的脚本并将 blob 下载到本地路径中FTP 服务器。
Can this be done via the blob file URL?
命令"Get-AzureStorageBlobContent"不接受URL作为参数。这意味着您需要编写代码或脚本来实现它。这是我写的一个简单的演示:
$url = "https://accountname.blob.core.windows.net/testcontainer/Test01.txt"
$separator = "://"
$option = [System.StringSplitOptions]::RemoveEmptyEntries
$temp = $url.Split($separator,4,$option)
$Protocol = $temp[0]
$HostName = $temp[1]
$Container = $temp[2]
$BlobName = $temp[3]
Or can I somehow have the file created in Powershell memory and then use $webclient.UploadFile to save it to FTP folder?
即使我们可以实现,将文件存储到 RAM 中也不是一个理想的选择。正如我上面提到的,如果您的 FTP 服务器是基于 Windows 的,请直接 运行 FTP 服务器上的脚本。
如果脚本由于任何原因不能运行在服务器上,那么请尝试共享FTP服务使用的文件夹并将其映射为计算机上的网络驱动程序这将 运行 脚本。这样您就可以将文件存储到此网络驱动程序中。
but can I instead have a custom path or remove the subfolders and save it as c:\myfolder\my_blob_file instead of c:\myfolder\dataload\files\my_blob_file?
当然,只需指定路径和文件名作为Destination参数即可:
注意:其实Azure存储上没有"folder"的概念。该路径是 blob 名称的一部分。下载 blob 时,可以通过在目标路径中指定文件名来重命名 blob。这样就不会在本地文件夹上创建附加文件夹。
============================================= ============================
更新:
This script is to be run from Azure as part of Azure Automation. But when I try to call the FTP server (which is currently my local machine) I get "Unable to connect to remote server" error.
您可能需要 Hybrid Runbook Worker 才能实现您的目标。
Azure 自动化中的 Runbook 无法访问本地数据中心的资源,因为它们 运行 在 Azure 云中。 Azure 自动化的混合 Runbook Worker 功能允许您 运行 运行 位于数据中心的机器上的书籍来管理本地资源。
I'm using the default 21 port and I also tried using my public IP address
不建议将您的 FTP 服务器暴露在互联网上。我建议使用 Hybrid Runbook Worker。
Also, how can I get the content of my blob file into a Powershell variable to work with it in the script?
据我所知,Get-AzureStorageBlobContent 不支持 return RAM 中的对象。您需要先下载内容,然后使用 Get-Content 获取文件内容。如果您使用 Hybrid Runbook Worker,您将能够在本地存储文件。
============================================= =================================
更新 2:
I am trying to understand as to how to call any external FTP server (which is currently on my machine for dev/test purpose, but may reside on any other external server in production), and I have to run it from a Powershell script in Azure Automation. So your reply: You may need Hybrid Runbook Worker to achieve your goal... will not work for me right?
Hybrid Runbook Worker 适合您。它让事情变得更容易。因为如果您使用 Hybrid Runbook Worker,则 Runbook 运行正在您的本地计算机上。
我可以将 blob 下载到我的本地计算机并将它们上传到 public FTP 服务器,没有任何问题。
Are you saying that currently there is no way to upload and download files from external FTP server from Azure Powershell Automation?
我没有成功将 blob 上传到 public FTP 服务器。当我尝试上传 blob 时出现异常,并且只有具有 blob 名称的空文件被上传到 FTP 服务器。这可能是一个权限问题,因为 PowerShell 脚本 运行 在沙盒中。这就是为什么我说 Hybrid Runbook Worker 让事情变得更简单的原因。
最后请注意:FTP对用户进行身份验证并以明文形式传输日期,这可能会导致安全问题。 FTPS 和 SFTP 比 FTP.
更安全
我正在尝试访问 PowerShell 中的 blob 文件并想将其直接保存到 FTP 服务器。如何才能做到这一点?这可以通过 blob 文件 URL 完成吗?或者我能以某种方式在 Powershell 内存中创建文件,然后使用 $webclient.UploadFile 将其保存到 FTP 文件夹吗?
与同一个下载相关的另一个问题是,有没有办法只复制文件而不是复制子目录?例如,我有一个像这样的 blob 文件:dataload/files/my_blob_file。当我使用命令 Get-AzureStorageBlobContent -Destination $destination_path 时,它将文件保存在相同的子文件夹结构中,但我可以改用自定义路径或删除子文件夹并将其另存为 c:\myfolder\my_blob_file c:\myfolder\dataload\files\my_blob_file?我想在上面的 FTP 服务器中完成此操作。
I am trying to access a blob file in PowerShell and want to save it directly to an FTP server.
如果您的 FTP 服务器是基于 Windows 的,那么您可以只 运行 FTP 服务器上的脚本并将 blob 下载到本地路径中FTP 服务器。
Can this be done via the blob file URL?
命令"Get-AzureStorageBlobContent"不接受URL作为参数。这意味着您需要编写代码或脚本来实现它。这是我写的一个简单的演示:
$url = "https://accountname.blob.core.windows.net/testcontainer/Test01.txt"
$separator = "://"
$option = [System.StringSplitOptions]::RemoveEmptyEntries
$temp = $url.Split($separator,4,$option)
$Protocol = $temp[0]
$HostName = $temp[1]
$Container = $temp[2]
$BlobName = $temp[3]
Or can I somehow have the file created in Powershell memory and then use $webclient.UploadFile to save it to FTP folder?
即使我们可以实现,将文件存储到 RAM 中也不是一个理想的选择。正如我上面提到的,如果您的 FTP 服务器是基于 Windows 的,请直接 运行 FTP 服务器上的脚本。
如果脚本由于任何原因不能运行在服务器上,那么请尝试共享FTP服务使用的文件夹并将其映射为计算机上的网络驱动程序这将 运行 脚本。这样您就可以将文件存储到此网络驱动程序中。
but can I instead have a custom path or remove the subfolders and save it as c:\myfolder\my_blob_file instead of c:\myfolder\dataload\files\my_blob_file?
当然,只需指定路径和文件名作为Destination参数即可:
注意:其实Azure存储上没有"folder"的概念。该路径是 blob 名称的一部分。下载 blob 时,可以通过在目标路径中指定文件名来重命名 blob。这样就不会在本地文件夹上创建附加文件夹。
============================================= ============================
更新:
This script is to be run from Azure as part of Azure Automation. But when I try to call the FTP server (which is currently my local machine) I get "Unable to connect to remote server" error.
您可能需要 Hybrid Runbook Worker 才能实现您的目标。
Azure 自动化中的 Runbook 无法访问本地数据中心的资源,因为它们 运行 在 Azure 云中。 Azure 自动化的混合 Runbook Worker 功能允许您 运行 运行 位于数据中心的机器上的书籍来管理本地资源。
I'm using the default 21 port and I also tried using my public IP address
不建议将您的 FTP 服务器暴露在互联网上。我建议使用 Hybrid Runbook Worker。
Also, how can I get the content of my blob file into a Powershell variable to work with it in the script?
据我所知,Get-AzureStorageBlobContent 不支持 return RAM 中的对象。您需要先下载内容,然后使用 Get-Content 获取文件内容。如果您使用 Hybrid Runbook Worker,您将能够在本地存储文件。
============================================= ================================= 更新 2:
I am trying to understand as to how to call any external FTP server (which is currently on my machine for dev/test purpose, but may reside on any other external server in production), and I have to run it from a Powershell script in Azure Automation. So your reply: You may need Hybrid Runbook Worker to achieve your goal... will not work for me right?
Hybrid Runbook Worker 适合您。它让事情变得更容易。因为如果您使用 Hybrid Runbook Worker,则 Runbook 运行正在您的本地计算机上。
我可以将 blob 下载到我的本地计算机并将它们上传到 public FTP 服务器,没有任何问题。
Are you saying that currently there is no way to upload and download files from external FTP server from Azure Powershell Automation?
我没有成功将 blob 上传到 public FTP 服务器。当我尝试上传 blob 时出现异常,并且只有具有 blob 名称的空文件被上传到 FTP 服务器。这可能是一个权限问题,因为 PowerShell 脚本 运行 在沙盒中。这就是为什么我说 Hybrid Runbook Worker 让事情变得更简单的原因。
最后请注意:FTP对用户进行身份验证并以明文形式传输日期,这可能会导致安全问题。 FTPS 和 SFTP 比 FTP.
更安全