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

Hello,

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

TIA,
ZS
zacksolutions
 
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
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1476
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",
private_key="/usr/local/fdfd/home/blah/blah")

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

# Closes the connection
srv.close()

# 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.

TIA,
ZS
zacksolutions
 
Posts: 12
Joined: Mon Aug 12, 2013 1:23 pm


Return to General Discussions

Who is online

Users browsing this forum: Bing [Bot] and 2 guests