【问题标题】:post a file which is there on remote linux machine in python在python中发布一个远程linux机器上的文件
【发布时间】:2020-04-01 08:29:53
【问题描述】:

我在远程 Linux 机器上有一个大文件。由于文件太大,我无法将其存储在本地 Windows 机器上。有什么方法可以直接将此远程文件发布到服务器?这里远程 Linux 机器确实有用户名和密码。

我有下面的代码来发布本地文件,即 bin_file_name:

system_update_file = {'file': (bin_file_name, open(str(bin_file_name), 'rb'), multipart/form-data')}
with requests.Session() as s:
   resp = s.post(request_url, params=None, files=system_update_file , auth=(amc_username_api, amc_password), verify=False)

如何使用上面的代码将远程文件POST到服务器?

【问题讨论】:

  • 是否要将文件从远程机器传输到另一台远程机器?
  • 没有。基本上我需要使用 POST 请求从远程机器上传文件到 WEB 服务器。

标签: python-3.x post python-requests


【解决方案1】:

我刚刚通过 Samba 使用网络共享共享了该文件。下面的代码为我完成了这项工作:

bin_file_path = "//remote_linux_machine_ip/folder/subfolder/actual_bin_file.bin"
system_update_file = {'file': (bin_file_path, open(str(bin_file_path), 'rb'), multipart/form-data')}
with requests.Session() as s:
  resp = s.post(request_url, params=None, files=system_update_file , auth=(amc_username_api, amc_password), verify=False)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-12-29
    • 2012-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-19
    相关资源
    最近更新 更多