1

I'm trying to automate uploading and downloading files from sftp server. I've come up with the idea of creating an SSIS package with Python script doing the heavylifting and then running the SSIS package in SQL server job. I need to establish the connection to sftp server going through proxy server. I've come across a paramiko - Python implementation of SSH. I'm racking my brain how to use it to connect to my sftp server.

Here's my code:

import paramiko

hostname = "my_sftp_host"
port=22
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
proxy = paramiko.proxy.ProxyCommand(
    '/usr/bin/nc --proxy my_server_proxy %s %d' \
    % (hostname, port) )
ssh = paramiko.Transport(sock=proxy)
ssh.connect(username='***', password='***')

sftp = paramiko.SFTPClient.from_transport(ssh)

And the errors I'm getting:

Traceback (most recent call last):
  File "C:\Python\PythON-Wtajemniczenie\LibrisSFTP.py", line 7, in <module>
    proxy = paramiko.proxy.ProxyCommand(
  File "C:\Users\arkadiusz.drezek\AppData\Local\Programs\Python\Python310\lib\site-packages\paramiko\proxy.py", line 62, in __init__
    self.process = subprocess.Popen(
  File "C:\Users\arkadiusz.drezek\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 969, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\arkadiusz.drezek\AppData\Local\Programs\Python\Python310\lib\subprocess.py", line 1438, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] Nie można odnaleźć określonego pliku

The error-message translated:

FileNotFoundError: [WinError 2] The system cannot find the file specified

7
  • 2
    I think the problem is that the "/usr/bin/nc" program doesn't exist in your filesystem. You are using Windows after all. Commented Dec 3, 2022 at 20:18
  • I totally agree with @ccre since the script is running on Windows, and this OS certainly does NOT have a /usr/bin/nc binary available. Commented Dec 3, 2022 at 20:23
  • That makes perfect sence, should I point out to the directory where paramiko package is installed? Commented Dec 3, 2022 at 20:33
  • 1
    If you don't have an executable named nc (usually NetCat is a Linux command) on your Windows path, then might find a Windows alternative like ncat or connect as in Windows SSH ProxyCommand /usr/bin/bash: line 0: exec: nc: not found on git bash - Stack Overflow Commented Dec 3, 2022 at 20:38
  • 1
    You can install the Nmap (nmap.org/download#windows), which is a very popular network scanner, and then you will find the ncat.exe binary in the installation folder. In the next step you need to replace /usr/bin/nc with the path to this binary. I think that is a quick solution to check if your script works. On my system the path to this binary is C:\Program Files (x86)\Nmap\ncat.exe. Commented Dec 3, 2022 at 21:41

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.