I have a local machine connected with internet.From my local machine i can access different machine or remote server.
On this remote server i have a excel/csv file.
I want to read this excel/csv file from my local machine using python programming.
How to read the excel/csv file located in different machine/remote server.
The pysftp package might help. Check out this writeup, which includes code examples of authenticating and fetching a file.
Related
I have a python script on my local machine related to a database. I can log in to that database server through a SSH connection. But how can I run my python file on that database server?
Do I need to upload my python script on that server machine? How can I do that?
I logged in to the database server through the ssh connection. I have access to that.
I ran my python file which is stored in my local machine on that server.
It shows "python3: can't open file .. No such file or directory"
I want to run the program and see the output.
I never used a server before (only my local machine), and recently I was given a server with Python files on it. I was also given SSH key and a password.
I'm trying to connect PyCharm to the server from my local machine so that I can write code on my local machine, upload the code to the server, and use code from existing files on the server.
The only website I found is this, and I followed the instructions to create an SSH interpreter, but I'm not sure what to do next (in order to see the files, write files to the server, etc,).
I have multiple windows servers in an internal network(meaning, not connected to the internet).
At the moment, I am pulling files from these servers using Windows Remote Desktop, for each server I have an IP address, login & password.
My goal is to use Python to automate this process, I want to be able to run a script that will access these internal servers and get files from them.
Is there any Python module that handles such tasks, or how should I approach this problem?
Windows' file sharing protocol is called SMB. There are some python libraries for this; the first google result for me was this one: https://pysmb.readthedocs.io/en/latest/
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.
I am executing a Python script on my Linux server that uses pysftp to connect to another server in order to read files that are sitting in a directory of that remote server. When I run the script, it fails out while connecting to the remote server and creates a text file with the title: 'This service allows sftp connections only.'
This file is created inside my project directory. Below is the part of my code that is failing:
def sftp_get_file(sftp_host, sftp_username):
with pysftp.Connection(sftp_host, sftp_username) as sftp:
# transfer file from remote to local
sftp.get(remote_file, local_file)
Code is very simple and works when I've tested it using my local server as the remote server. When I tested it in the new environment by actually depending on SFTP, then it failed. Any suggestions? Is pysftp using SSH at some point when it should be using only SFTP?
Turns out the problem was due to me performing sftp.execute('ls') a couple lines down in the script. The server I was remoting onto only supported sftp commands and that command was forbidden.