8000 Using a trailing forward slash in Windows causes problems · Issue #189 · jbardin/scp.py · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Using a trailing forward slash in Windows causes problems #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
greenfoo opened this issue Jan 5, 2024 · 0 comments
Open

Using a trailing forward slash in Windows causes problems #189

greenfoo opened this issue Jan 5, 2024 · 0 comments
Labels

Comments

@greenfoo
Copy link
greenfoo commented Jan 5, 2024

Short description

If I copy "src" to "dst", it works.
If I copy "src/" to "dst", it fails (only when running on Windows).

More details

Let' s see it with an example.

First of all, in Linux, let's create a test folder structure:

$ mkdir data
$ touch data/1.txt
$ touch data/2.txt
$ mkdir data/3
$ touch data/3/3.txt

$ tree
.
└── data
   ├── 1.txt
   ├── 2.txt
   └── 3
       └── 3.txt

Next, let's create an example (test.py) that makes use of the scp library:

import paramiko
import os
import sys
import scp

c=paramiko.SSHClient()
c.load_system_host_keys(filename=os.devnull)
c.load_host_keys(filename=os.devnull)
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect("example.com", username="joe", password="doe")

s=scp.SCPClient(c.get_transport(), sanitize=lambda x: x, socket_timeout=60)

s.put(sys.argv[1], "/tmp", recursive=True)

Finally, let's use this script to copy the folder data to a remote server:

$ test.py data

$ ssh example.com tree /tmp
/tmp
└── data
    ├── 1.txt
    ├── 2.txt
    └── 3
        └── 3.txt

We can also run the same script with "data/" instead of "data" if we want to transfer the contents of the folder and not the folder itself:

$ test.py data/

$ ssh example.com tree /tmp
/tmp
├── 1.txt
├── 2.txt
└── 3
    └── 3.txt

So far, so good. The problem comes when we try the same thing in Windows: the first example (data) works, but the second example (data/) results in this error:

c:\work>python test.py data/
Traceback (most recent call last):
  File "c:\work\test.py", line 13, in <module>
    c2.put(sys.argv[1], "/tmp", recursive=True)
  File "C:\Program Files\Python39\lib\site-packages\scp.py", line 203, in put
    self._send_recursive(files)
  File "C:\Program Files\Python39\lib\site-packages\scp.py", line 373, in _send_recursive
    self._chdir(last_dir, asbytes(root))
  File "C:\Program Files\Python39\lib\site-packages\scp.py", line 361, in _chdir
    self._send_pushd(to_dir)
  File "C:\Program Files\Python39\lib\site-packages\scp.py", line 387, in _send_pushd
    self._recv_confirm()
  File "C:\Program Files\Python39\lib\site-packages\scp.py", line 415, in _recv_confirm
    raise SCPException('No response from server')
scp.SCPException: No response from server
@remram44 remram44 added the bug label Jan 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants
0