Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python ftplib.error_perm: 530 Login authentication failed

I want to write a script to connect my FTP server , but it can not work for me.

from ftplib import FTP
ftp=FTP()
ftp.set_debuglevel(2)
ftp.connect('192.169.137.100')
ftp.login('test','test')
ftp.dir()
ftp.close()

and when build this script, I got these information

*get* '220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------\r\n'
*get* '220-You are user number 1 of 50 allowed.\r\n'
*get* '220-Local time is now 23:46. Server port: 21.\r\n'
*get* '220-This is a private system - No anonymous login\r\n'
*get* '220 You will be disconnected after 15 minutes of inactivity.\r\n'
*resp* '220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------\n220-You are user number 1 of 50 allowed.\n220-Local time is now 23:46. Server port:  21.\n220-This is a private system - No anonymous login\n220 You will be   disconnected after 15 minutes of inactivity.'
*cmd* 'USER test'
*put* 'USER test\r\n'
*get* '331 User test OK. Password required\r\n'
*resp* '331 User test OK. Password required'
*cmd* 'PASS ****'
*put* 'PASS ****\r\n'
*getTraceback (most recent call last):
 File "D:\photoWebSite\py_test.py", line 9, in <module>
* '530 Login authentication failed\r\n'
*resp* '530 Login authentication failed'
    ftp.login('test','test')
    File "D:\LinuxSL\python27\lib\ftplib.py", line 393, in login
    if resp[0] == '3': resp = self.sendcmd('PASS ' + passwd)
File "D:\LinuxSL\python27\lib\ftplib.py", line 249, in sendcmd
    return self.getresp()
File "D:\LinuxSL\python27\lib\ftplib.py", line 224, in getresp
    raise error_perm, resp
ftplib.error_perm: 530 Login authentication failed

I hope some help please .

like image 928
allen-x Avatar asked Jan 21 '17 07:01

allen-x


2 Answers

You may try to use FTP_TLS as following:

from ftplib import FTP_TLS
ftp=FTP_TLS()
ftp.set_debuglevel(2)
ftp.connect('192.169.137.100', 22)
ftp.sendcmd('USER test')
ftp.sendcmd('PASS test')
ftp.dir()
ftp.close()
like image 141
tomcy Avatar answered Sep 30 '22 21:09

tomcy


I used ftplib and was unable to connect becuase of error_perm, used pysftp and it worked for me.

import pysftp
cnopts = pysftp.CnOpts()
cnopts.hostkeys = None   
myHostname = "abc.org"
myUsername = "username"
myPassword = "password"

with pysftp.Connection(host=myHostname, username=myUsername, password=myPassword, cnopts=cnopts) as sftp:
    print ("Connection succesfully stablished ... ")
    directory_structure = sftp.listdir_attr()
    for attr in directory_structure:
        print (attr.filename, attr)
like image 42
Hari_pb Avatar answered Sep 30 '22 21:09

Hari_pb