问题描述
我正在尝试将内容从源目录 C:\report
移动到远程目录 remote_server_path/Test
.下面是我正在尝试的代码.它不只是移动 C:\report
的内容,而是沿着文件夹移动到远程位置.关于如何无法做到这一点的任何建议?
I am trying to move the contents from source directory C:\report
to the remote directory remote_server_path/Test
. Below is the code that I am trying with. Instead of just moving the contents of C:\report
, it moves along the folder as such to the remote location. Any recommendations on how this could not be done?
import paramiko
from scp import SCPClient
import os
# create variables
host = "host"
username = "uname"
password = "password"
# Move files from network drive to marketing server
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect(hostname=host, username=username, password=password)
scp = SCPClient(ssh.get_transport())
scp.put('C:\\report', recursive=True, remote_path='remote_server_path/Test')
推荐答案
使用 C:\report\*
选择文件夹内的文件.
scp.put('C:\\report\\*', recursive=True, remote_path='remote_server_path/Test/')
强制性警告:请勿使用 AutoAddPolicy
– 您将失去针对 MITM 攻击 这样做.如需正确的解决方案,请参阅Paramiko未知服务器".
Obligatory warning: Do not use AutoAddPolicy
– You are losing a protection against MITM attacks by doing so. For a correct solution, see Paramiko "Unknown Server".
这篇关于使用 SCPClient Python 仅传输目录的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!