Python scp copy file with spaces in filename

后端 未结 3 1748
离开以前
离开以前 2021-01-26 04:53

I\'m trying to copy files in local network with scp. It\'s working well with filenames without spaces, but it crash with. I\'ve tried to replace \" \" with \"\\ \" as this exemp

3条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-26 05:48

    You may keep local file file_pc as is (pipes.quote will escape the spaces). The remote file should be changed:

    import pipes
    
    file_pi = 'pi@192.168.X.X:/home/pi/folder/file with space.smth'
    host, colon, path = file_pi.partition(':')
    assert colon
    file_pi = host + colon + pipes.quote(path)
    

    i.e., user@host:/path/with space should be changed to user@host:'/path/with space'

提交回复
热议问题