Connecting to SFTP server via Windows' Command Prompt [duplicate] - python

This question already has answers here:
Secure FTP using Windows batch script
(3 answers)
Closed 7 years ago.
I'm wondering if there's any way to connect SFTP server with Windows' Command Prompt, by only executing batch file.
Do I need to install additional software? which software?
The purpose is to do pretty basic file operations (upload, delete, rename) on remote SFTP server by executing a batch file.
And by the way, I have heard about python's Fabric library, and I wonder whether it's better solution than the batch script for the mentioned basic file operations?
Thanks a lot!

The built in FTP command doesn't have a facility for security. You can use winscp, an open source free SFTP client and FTP client for Windows.

Try using cURL. It allows to set up file transfers from the command line and supports SSL.
See http://www.unixlore.net/articles/using-curl-for-ftp-over-ssl-file.html

Related

I need to write a python script which will make a passwordless connection from one server (server1) to another remote server(server2) [duplicate]

This question already has answers here:
Pass commands as input to another command (su, ssh, sh, etc)
(3 answers)
Closed last year.
I have successfully created public private keys to make passwordless ssh connection.
I need to make connection with remote server, go to a particular path, and append some input to sample.log file.
Currently I am using os.system("ssh xxx#aaa.vvv.com") and then the steps to append the input to sample.log file. But my script stops only aftwr making connection with using os.system("ssh xxx#aaa.vvv.com").
Paramiko Module is best suited for it.
I use it personally to make connections and execute comand from one device to another.
You can find more detailed information of paramiko on https://www.paramiko.org

Is their some means of coding and running Python on a Raspberry PI from a PC? [duplicate]

This question already has answers here:
Run local python script on remote server
(5 answers)
Closed 6 years ago.
So far, SSH is all I can think of. Send a command line like python <dosometing., and interpret the response. I am, however, hoping for a lower level library, where I can enter the Python command in my interpreter's REPL, and have that command execute on the Pi, and return the result to my REPL.
Please no questions why don't I just SSH straight into the Pi and use its Python directly. I don't want to use an SSH session to write Python on my headless Pi. I want a Windows Python REPL that talks to the Raspbian Python transpiler. This is for an experimental task that is part of a much larger project about .NET and Pi communication.
First thing that comes to my mind is to create a TCP server-client app. Server would reside on RPi, and waiting on connections. When the command arrives from client, server will execute it (using subprocess.Popen or even maybe os.system). Client can get whole output back (in the first case), or just exit status (in the second case).

Using python to ssh into multiple servers and grab the file with the same postfix

I normally use a bash script to grab all the files onto local machine and use glob to process all the files. Just wondering what would be the best way to use python (instead of another bash script) to ssh into each server and process those files?
My current program runs as
for filename in glob.glob('*-err.txt'):
input_open = open (filename, 'rb')
for line in input_open:
do something
My files all have the ending -err.txt and the directories where they reside in the remote server have the same name /documents/err/. I am not able to install third party libraries as I don't have the permission.
UPDATE
I am trying to not to scp the files from the server but to read it on the remote server instead..
I want to use a local python script LOCALLY to read in files on remote server.
The simplest way to do it is to use paramico_scp to use ssh copy from the remote server (How to scp in python?)
If you are not allowed to download any libraries, you can create SSH key pair so that connecting to server does not require a password (https://www.debian.org/devel/passwordlessssh). You then can for each file do
import os
os.system('scp user#host:/path/to/file/on/remote/machine /path/to/local/file')
Note that using system is usually considered less portable than using libraries. If you give the script that use system('scp ...') to copy the files and they do not have SSH key pair set up, they will experience problems
Looks like you want to use a local Python script remotely. This has been answered here.

python: how to run scripts over ssh remotely [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Execute arbitrary python code remotely - can it be done?
I wrote a memory usage check function and it runs fine on one server (say 10.100.110.10).
But I need to run the same script remotely on 10.100.110.11 from 10.100.110.10. I can ssh to 10.100.110.11 from 10.100.110.10. Is there any way to implement that using python built in modules?
I can't use any new modules like Paramico and Unix command
ssh -n user#10.100.110.11 "df -m"
works fine.
If it is not possible, how can I ssh to 10.100.110.11 using a built in Python module?
You cannot remotely run Python code if you're not accessing the Python interpreter on the other side. You could sent the code the the Python's interpreter standard input, but you still have to send the code.
The other solution would be to make your code remote-compatible, and replace all systems calls by their equivalents over SSH (using Paramiko for example).

open (and maintain) remote connection with python

I'm using Python to transfer (via scp) and database a large number of files. One of the servers I transfer files to has odd ssh config rules to stop too many ssh requests from a single location. The upshot of this is that my python script, currently looping through files and copying via os.system, hangs after a few files have been transferred.
Is there a way in which Python could open up an ssh or other connection to the server, so that each file being transferred does not require an instance of ssh login?
Thanks,
You probably want to look into the paramiko module.
There's a Copy files over SSH using paramiko recipe using it that might be helpful.
Check out SFTP in the Python module Paramiko. You can do multiple file transfers in a single session.
This is not really python specific, but it probably depends on what libraries you can use.
What you need is a way to send files through a single connection.
(This is probably better suited to superuser or severfault.com though.)
Create tarfile locally, upload it and unpack at target?
Maybe you could even run 'tar xz' remotely and upload the file on stdin over SSH? (As MichaelDillon says in the comment, Python can create the tarfile on the fly...)
Is SFTP an option?
Rsync over SSH?
Twisted is an async library that can handle many sockets/connections at once. Is probably overkill for your solution though,
Hope it helps.

Categories

Resources