Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Installing the scp module via pip (in stash)
-
scp is "built in" to stash.
scp LOCAL_FILE USER@REMOTE_HOST:/PATH
-
@JonB Yes, it is. I use scp in stash, but was hoping to be able to call scp from inside a python3 script.
Something like this:from paramiko import SSHClient from scp import SCPClient ssh = SSHClient() ssh.load_system_host_keys() ssh.connect('example.com') with SCPClient(ssh.get_transport()) as scp: scp.put('test.txt', 'test2.txt') scp.get('test2.txt')
I know there is an scp python module:
python scp moduleCan I call a Stash command from a python3 file to run scp from stash?
Sorry if I am not making sense.
Thank you again, since I feel like I keep asking you questions. -
@FarmerPaco, if it helps, this is not exactly scp, but does the same thing:
#coding: utf-8 import paramiko s = paramiko.SSHClient() s.set_missing_host_key_policy(paramiko.AutoAddPolicy()) s.connect("<ip>", port, username='...', password='...', timeout=4) sftp = s.open_sftp() sftp.mkdir(remote_dir) # if needed sftp.put(local_path, remote_path) s.close()
-
Stash let's you import it, and run commands via script. Or you could add the stash/bin path to sys.path, and then run_py the module.
-
@mikael thanks for this. I will check it out later, but it looks like something I should know.
I am assuming that in s.connect the port is 22 for sftp.
Thanks for the pointer. -
@JonB thanks for pointing out my options. Will probably try installing the ssh python module first.
Normally when I think of ssh I think of Bash, and since Stash (from what I read) is really just emulating a shell, I wasn’t sure if that would get in the way.
I guess there is only one way to find out.
Again, thanks. -
Paramiko comes preinstalled, which is what stash uses internally. You can read the stash/bin/scp.py and see what it does, it is not complicated.
Trying to install any modules not made for pythonista is going to result in disappointment.
-
@JonB
Trying to install any modules not made for pythonista is going to result in disappointment.
is so true but I like your humor 😂 -
@JonB Thanks again for your time
I’m going to install PyDrive on my Pi zero to familiarize myself with the normal process so I can debug where along the process my pythonista install is failing.I did check the site packages and saw the Stash running 2.7 installs a more updated version of pyasn1 (v. 2.1) where as stash runing at 3.6 installs an earlier version of pyasn1 (v.1.7). This seemed strange.
Thanks again for your feedback. I will finish a PyDrive install on Rasbian (debian) which should be straightforward and then see where I am going wrong on Pythonista.
I will also check stash/bin/scp.py -
Did you post your traceback for pydrive issues?
-
BTW, iirc, monkeylord in stash has the capability to "mount" Google drive folder.
-
@JonB said:
BTW, iirc, monkeylord in stash has the capability to "mount" Google drive folder.
The
mount
-command currently only supports dropbox, ftp, zipfiles and other directories. I am thinking about rewriting it to usepyfilesystem2
instead, but this may still take a while.@FarmerPaco said:
I did check the site packages and saw the Stash running 2.7 installs a more updated version of pyasn1 (v. 2.1) where as stash runing at 3.6 installs an earlier version of pyasn1 (v.1.7). This seemed strange.
Interesting... Are you using StaSh version
0.7.2
? I recently changedpip
to respect the python version when installing new packages, but pyasn1 should work for both... Also, are you sure about the version ofpyasn1
? According to pypi the most recent version is0.4.5
. -
@bennr01 I am not running 7.2. Running 7.1 and that might be part of my problem. Will update shortly.
Regarding pyasn1, versions 2.1 to 4.2 were released in 2017.
I believe I am looking at the version of pyasn1 correctly. I only did so because in the original guide I was following @JonB specifically installed a version of pyasn1 after PyDrive. I wanted to make sure my version was the same or higher.
I looked in: /site-packages-2/pyasn1/init.py
version = '0.2.1'
Then I looked in: /site-packages-3/pyasn1/init.py
version = '0.1.7'
Not sure why these would be different, or why the version in my python3 would be an earlier version. I am thinking to delete these packages from PyDrive and dependencies, update stash and then reinstall with pip.
Also plan to do a PyDrive on my raspberry pi today and compare the files.
I am still new to this stuff but what to understand better what’s happening under the hood. -
@bennr01 just want to confirm that installing PyDrive via pip on raspbian downloads pyasn1 0.4.5
This is not the same with pip in stash 7.1.
But I honestly don’t know how much it matters.
-
Just to follow up on this matter. After struggling with PyDrive in pythonista for a while with resulting errors, I often to just go ahead and try the Google Drive API.
There is a super simple tutorial in codelabs:
https://codelabs.developers.google.com/codelabs/gsuite-apis-intro/#0Everything installs nicely and runs well.It even lets you complete the authentication in a separate browser if need be. I did the authentication on my raspberry pi and scped the secrets.jason and since then it works perfectly.
Just in case anyone wants to access and G suite files, you should know that pip in stash running in python3 nicely installs google-api-python-client and oauth2client in the site-packages-3 (which is all you need for Google Drive API).