Copy File from Windows Host to Linux [Python] - python

What are the different modules/ways to copy file from a windows computer to a linux server available in python
I tried using ftplib api to connect to the windows server but i m unable to do with the error - socket.error: [Errno 111] Connection refused
What are the other modules that i can connect to a windows computer to copy or list the files under a directory

If you have access to linux server, and the file generated on windows automatically, you can do the folowing:
Generate ssh-key on your windows maching
Add it to authorized_hosts of the linux machine
Install simple console scp tool on windows
Write simple cmd-script to copy file with help of scp, something like:
scp c:\path\to\file.txt user#linuxhost.local:/home/user/file.txt
Run this script automatically every time, then the file is generated on windows host.

Related

NoValidConnectionError on Paramiko in Python

ssh_client =paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh_client.load_system_host_keys()
ssh_client.set_missing_host_key_policy(paramiko.WarningPolicy)
ssh_client.connect(hostname='abc',username='admin',password='admin')
with SCPClient(ssh_client.get_transport()) as scp:
scp.put(local_path='example.txt',remote_path='/abc')
I am trying to connect to a Windows system and send a file example.txt to it. But if I run the script, it gives the following error when sending a file to a windows system
paramiko.ssh_exception.NoValidConnectionsError: [Errno None] Unable to connect to port 22 on 'IP Address'
Help would be appreciated.
Edit: The Windows system that I am sending the file to runs a Windows 2008 server.
If you want to connect with Paramiko SSH/SFTP/SCP library to a machine, the machine must be running SSH/SFTP/SCP server.
Windows does not come with SSH/SFTP/SCP server running by default.
See Windows SSH Servers? question on Super User.

How to delete file on Windows Remote Server?

How to delete specific file on Windows Remote Server using Python?
I'm able to connect to remote Windows Server using WMI, but not sure how to delete file remotely on windows server.

How to copy a file from one windows server to another remote windows server using python?

I connect remote server(via Remote desktop) using username/password.
How can I copy one file from my machine to that remote windows machine using python?

Transfer file from local machine to remote windows server using python

How can I easily copy a local file to a remote server using python?
I don't want to map the drive to my local machine and the windows server requires a username and password.
The local machine is also a windows machine.
Examples I've seen are with linux and mapping the drive. Unfortunately that's not an option for me.
You can use the subprocess module or os.system to launch a command into a windows shell. Then you can use Powershell or cmd instructions.

Error when connecting to SFTP server using Python Pysftp

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.

Categories

Resources