Giter Club home page Giter Club logo

Comments (9)

byteskeptical avatar byteskeptical commented on July 23, 2024

The first issue is definitely a bug that will require some additional logic prior to deal with both absolute types (windows & unix) in a semi-intelligent manner. As for the second, the intent of the put_d function is to limit the content uploaded to a single directory level, which I'm sure you grasp just fine. The call to mkdir_p is an attempt to provide the user with the freedom of choice as to whether they want just the content or the whole structure copied by being explicit in the remotedir parameter. In your example if you want the "local_folder" sub-folder created as well you should pass the remotedir parameter as "folder/local_dir" which should give you the desired result. Please let me know if this is not the case in your testing. Also, any suggestions on making the description more concise for others in this respect would be greatly appreciated.

from sftpretty.

Johnmaras avatar Johnmaras commented on July 23, 2024

I see your point. As I understand, for the put_d() to run successfully, one must run something like put_d("local_folder", "") while having already created the folder "local_folder" in the remote path. I tested it and runs correctly. So, as per the above put_d example, my local folder's ("local_folder") contents will be copied to the remote folder "/local_folder".

Also, what is the purpose of put_r()? I tried calling put_r("local_folder", "") but I get the "Path not found" error. For the purpose of testing put_r(), I added a sub-folder ("test_folder") under my "local_folder". I tried creating the remote path ("/local_folder/test_folder") following the aforementioned logic, but no luck. I also tried it without manually creating the remote paths first, but still nothing. How should I invoke put_r()?

from sftpretty.

byteskeptical avatar byteskeptical commented on July 23, 2024

Yes, kind of but you shouldn't have to create it first if the initial call is something like put_d("local_folder", "folder/local_folder"). If that is not working then there is additional work to be done on that front.

As for put_r it can technically be used to achieve the same result but it will recursively upload all sub-folders and their content(s) if they exist. If there are no sub-folders as in your original call to put_d then they behave largely the same. At minimum the remotedir parameter for both put_d and put_r has to be "." and should never be empty. Otherwise we are making assumptions about expected behavior that may not be consistent in all use cases. This however is not the case for the put call which will technically allow you to not pass a remotedir parameter by making the assumption that you want to maintain the localfile's name and simply upload it to the remote root directory.

from sftpretty.

byteskeptical avatar byteskeptical commented on July 23, 2024

Could you post the full trace for the first issue like you did for the second please, I'm having some issues reproducing the behavior.

from sftpretty.

Johnmaras avatar Johnmaras commented on July 23, 2024

Sorry for the late reply.

Here is the traceback:
Traceback (most recent call last):
File "C:/Users/johnm/PycharmProjects/test_sftp/main.py", line 12, in
con.put_d("C:\\Users\\johnm\\PycharmProjects\\test_sftp\\test_dir", ".")
File "C:\Users\johnm\PycharmProjects\test_sftp\venv\lib\site-packages\sftpretty\__init__.py", line 608, in put_d
for localpath in Path(localdir).iterdir()
File "C:\Users\johnm\PycharmProjects\test_sftp\venv\lib\site-packages\sftpretty\__init__.py", line 609, in
if localpath.is_file()
File "C:\Users\johnm\AppData\Local\Programs\Python\Python37\lib\pathlib.py", line 900, in relative_to
.format(str(self), str(formatted)))
ValueError: 'C:\\Users\\johnm\\PycharmProjects\\test_sftp\\test_dir\\file.txt' does not start with '\\'

I tried calling:

  1. put_d("C:\\Users\\johnm\\PycharmProjects\\test_sftp\\test_dir", "test_dir")
  2. con.put_d("C:\\Users\\johnm\\PycharmProjects\\test_sftp\\test_dir", ".")

Both cases yield the same error. In case of number 1 the "test_dir" gets created, if that's of any help.

from sftpretty.

byteskeptical avatar byteskeptical commented on July 23, 2024

Can you confirm if the linked pull request solves the issue?

from sftpretty.

Johnmaras avatar Johnmaras commented on July 23, 2024

Same error.

Traceback (most recent call last):
  File "C:/Users/johnm/PycharmProjects/sftpretty_original/.other/file.py", line 17, in <module>
    sftp_con.put_d("C:\\Users\\johnm\\PycharmProjects\\sftpretty_original\\.other\\test_sftp\\test_dir", "test_dir")
  File "C:\Users\johnm\PycharmProjects\sftpretty_original\sftpretty\__init__.py", line 619, in put_d
    for localpath in Path(localdir).iterdir()
  File "C:\Users\johnm\PycharmProjects\sftpretty_original\sftpretty\__init__.py", line 620, in <listcomp>
    if localpath.is_file()
  File "C:\Program Files\Python37\lib\pathlib.py", line 900, in relative_to
    .format(str(self), str(formatted)))
ValueError: 'C:\\Users\\johnm\\PycharmProjects\\sftpretty_original\\.other\\test_sftp\\test_dir\\file1.txt' does not start with '\\'

Folder structure:

test_sftp
    |   file2.txt
    |
    \---test_dir
            file1.txt

from sftpretty.

byteskeptical avatar byteskeptical commented on July 23, 2024

Can you verify your pathlib module version pip3 show pathlib? Or can you try on a version of Python >= 3.8. I'm starting to think this may be related to https://bugs.python.org/issue19918.

from sftpretty.

byteskeptical avatar byteskeptical commented on July 23, 2024

I'll leave this open for another week to give you some additional time. I understand other things maybe taking your time so if you find this to not be the aforementioned bug we can re-open this issue. Thanks for the feedback!

from sftpretty.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.