4

I'm running into some very strange behaviour when trying to connect to a ftp server using ftplib. What I'm doing is:

import ftplib
ftp = ftplib.FTP('my-ftp-server')
ftp.login('user ', 'pass')

Now if I run these from a python interpreter it work fine and I get:

'230 Login successful.'

But I want to have these in a nice script that can do stuff for me. When I put these all in some python script and run:

 python my_ftp_stuff.py

I get:

 ftplib.error_perm: 530 Login incorrect.

I really am clueless as to what can cause this weird behaviour. Does anyone have any tips on what to try?

Best regards

Bogdan
  • 8,017
  • 6
  • 48
  • 64

2 Answers2

5

You have a space (' ') character in your username field.

danodonovan
  • 19,636
  • 10
  • 70
  • 78
  • Wow this is embarassing. And I've spend about 2 hours banging my head against the wall what this could be. Also funny thing is that these are not my actual credentials so I accidentally added a space here aswell :D – Bogdan Feb 19 '13 at 14:34
  • Don't sweat it, I've still got wall imprints on my head too. – danodonovan Feb 19 '13 at 14:39
2

You should pass login & password to __init__ instead of login method:

import ftplib
ftp = ftplib.FTP('my-ftp-server', 'login', 'password')
print(ftp.dir())
  • yes but that is just un initialisation of ftp object and if you run in ipython or need waiting for other staff your connection can be close after default timeout. Also ftp.connect(host, timeout=x) ftp.login(user, passwd) is more safe and can easy reconnect with error catching – GeoStoneMarten Mar 14 '17 at 15:13