pysftp.connection.cd() doesn't seem to work as expected - any ideas why

DK786

having trouble getting the pysftp.connection.cd() working - not sure what I am doing wrong or what the issue is. I can achieve what I need by passing the full remote path into the relevant methods but if try to change the remote active directory I get error. Relevant code is below:

with ps.Connection('hostname or IP address', username='username', password='secret', cnopts=cnopts) as conn:
    print("Connection successful....")
    print(conn.listdir()) # this works
    print(conn.listdir(remote_location))  # this works
    with conn.cd(remote_location):  # this throws an error
        print(conn.listdir())  

The error I get is below here:

File "C:\Users\username\.conda\envs\data_wrangling\lib\site-packages\pysftp\__init__.py", line 508, in cd
    self.cwd(remotepath)
  File "C:\Users\username\.conda\envs\data_wrangling\lib\site-packages\pysftp\__init__.py", line 524, in chdir
    self._sftp.chdir(remotepath)
  File "C:\Users\username\.conda\envs\data_wrangling\lib\site-packages\paramiko\sftp_client.py", line 659, in chdir
    if not stat.S_ISDIR(self.stat(path).st_mode):
OverflowError: mode out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\Users\username\my_code\python\mears_to_er_interface\sftp_chdir_test.py", line 41, in <module>
    with conn.cd("remote_location"):
  File "C:\Users\username\.conda\envs\data_wrangling\lib\contextlib.py", line 112, in __enter__
    return next(self.gen)
  File "C:\Users\username\.conda\envs\data_wrangling\lib\site-packages\pysftp\__init__.py", line 511, in cd
    self.cwd(original_path)
  File "C:\Users\username\.conda\envs\data_wrangling\lib\site-packages\pysftp\__init__.py", line 524, in chdir
    self._sftp.chdir(remotepath)
  File "C:\Users\username\.conda\envs\data_wrangling\lib\site-packages\paramiko\sftp_client.py", line 659, in chdir
    if not stat.S_ISDIR(self.stat(path).st_mode):
OverflowError: mode out of range
Martin Prikryl

Paramiko uses Python stat module in the SFTPClient.chdir implementation to check if the path is a folder (and not a file).

The problem is that the Python stat module can work with 16-bit permissions only. Your SFTP server returns permissions with 17th bit set. That results in the OverflowError. There's not much you can do about it. See this Python issue: stat.S_ISXXX can raise OverflowError for remote file modes.

Just avoid using the SFTPClient.chdir. The only other place where Paramiko currently uses the stat module is the SFTPAttributes.__str__. Otherwise you should be safe.

I've reported this to the Paramiko project: https://github.com/paramiko/paramiko/issues/1802

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

pysftp connection change directory doesn't work

useState() - doesn't seem to work as expected

Script defer doesn't seem to work as expected

setLocation on a JButton doesn't seem to work as expected

Mockito thenAnswer doesn't seem to work as expected

Why doesn't it work as expected?

Why doesn't this unexpand seem to work?

Strcmp doesn't work and I don't seem to understand why - transformation to ASCII code makes the program work as expected though

Why doesn't "cd" work in a shell script?

Completed property in Angular Material Stepper doesn't seem to work as expected

Angular 8 .next doesn't seem to work as expected

Rails SQL select, doesn't seem to work as expected with the CASE statement

java.util.Date equals() doesn't seem to work as expected

golang TCPConn.SetWriteDeadline doesn't seem to work as expected

AMQP.Net Credit doesn't seem to work as expected

Object_hook in json module doesn't seem to work as expected

The date functions in snowflake doesn't seem to work as expected

Any ideas why MyStack doesn't conform to ProtoStack?

My linked list method for counting occurences of object doesn't seem to be terminating. Any ideas?

Why doesn't this simple for loop work as expected?

Why doesn't this softlink work as expected?

Why doesn't regex '.+' work as expected?

Why doesn't PHP Increment work as expected

Why findFirstVisibleItemPosition doesn't work as expected?

Why doesn't umask work as expected?

Why doesn't the rename command work as expected?

Why doesn't sizeof work as expected?

Why doesn't this regex work as expected in Java?

Why TrimLeft doesn't work as expected?