ftp in python

A forum for general discussion of the Python programming language.

ftp in python

Postby zacksolutions » Sun Jan 26, 2014 8:57 pm


Does anyone have an example of how I can connect to an ftp site in python that requires a private key authentication?

Posts: 12
Joined: Mon Aug 12, 2013 1:23 pm

Re: ftp in python

Postby metulburr » Mon Jan 27, 2014 3:34 am

What code have you tried? Have you read http://docs.python.org/2/library/ftplib.html
we will be moving to python-forum.io on October 1 2016
more details here
User avatar
Posts: 2244
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: ftp in python

Postby zacksolutions » Mon Jan 27, 2014 6:25 pm

I am trying to use the pysftp module.

Here's what I have so far:

Code: Select all

import os
import shutil
import pysftp

srv = pysftp.Connection(host="blah.com", username="blah",

# Get the directory and file listing
data = srv.listdir()

# Closes the connection

# Prints out the directories and files, line by line
for i in data:
    print i

When I run this code, I get the following error message:

File "/usr/local/lib/python2.7/dist-packages/pysftp.py", line 76, in __init__
File "/usr/lib/python2.7/dist-packages/paramiko/pkey.py", line 198, in from_private_key_file
key = cls(filename=filename, password=password)
File "/usr/lib/python2.7/dist-packages/paramiko/dsskey.py", line 50, in __init__
self._from_private_key_file(filename, password)
File "/usr/lib/python2.7/dist-packages/paramiko/dsskey.py", line 175, in _from_private_key_file
data = self._read_private_key_file('DSA', filename, password)
File "/usr/lib/python2.7/dist-packages/paramiko/pkey.py", line 280, in _read_private_key_file
data = self._read_private_key(tag, f, password)
File "/usr/lib/python2.7/dist-packages/paramiko/pkey.py", line 290, in _read_private_key
raise SSHException('not a valid ' + tag + ' private key file')
paramiko.SSHException: not a valid DSA private key file

I generated a new private key file and submitted it to IT guys to add to my profile for the destination ftp server machine.
I'll see how it goes.

Posts: 12
Joined: Mon Aug 12, 2013 1:23 pm

Return to General Discussions

Who is online

Users browsing this forum: No registered users and 6 guests