Comments (9)
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.
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.
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.
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.
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:
- put_d("C:\\Users\\johnm\\PycharmProjects\\test_sftp\\test_dir", "test_dir")
- 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.
Can you confirm if the linked pull request solves the issue?
from sftpretty.
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.
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.
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)
- Typo in argument name - tires/tries HOT 2
- calling basicConfig at this level for a library that should be embedded changes all dowstream logs HOT 1
- Need less logging HOT 4
- Windows: No hostkey for host [localhost] found. HOT 16
- AttributeError: str object has no attribute root for put_d in localdir.root HOT 1
- Windows: No hostkey for host [localhost] found - Part 2 HOT 1
- Question: Is the put_d method expected to upload files to remote path with the same path as localpath? HOT 3
- Put_d has issue in creating remote directory HOT 1
- get_r copies remote folder structure into localdir HOT 3
- ChannelException while using get_r HOT 2
- Connection duplicated HOT 2
- Doesn't use SSH config file. HOT 8
- Can't catch IOError when retry is enabled during uploading a file HOT 2
- Feature Request: able to set max workers for any ThreadPoolExecutor HOT 1
- sftpretty adding console log to root logger HOT 2
- when knowhosts directory doesn't exist. it will keep throwing FileNotFoundError regardless we set hostkeys=None HOT 3
- paramiko.ssh_exception.SSHException: No hostkey for host [] found. HOT 2
- pysftp walktree method missing for drop in replacement HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sftpretty.