-1

i'm trying to access an ftp library using a python script the address of the library is something like this: ftp://XX.XXX.XXX.XXX/

so i used this code from pythonforbegginers :

import ftplib
ftp = ftplib.FTP('ftp.sunet.se', 'anonymous', 'anonymous@sunet.se')
print "File List: "
files = ftp.dir()
print files

and i tried to use it to suit my case like this:

ftp = ftplib.FTP('ftp.xx.xxx.xxx.xxx/','maklit' ,'maklit@xx.xxx.xxx.xxx/')
print ("File List: ")
files = ftp.dir()
print (files)

but i get the error : "for res in _socket.getaddrinfo(host, port, family, type, proto, flags): socket.gaierror: [Errno 11004] getaddrinfo failed "

how do i get it to work? what am i doing wrong? thanks.

Adam
  • 1
  • First argument is probably either a hostname or an IP address. Looks like you're passing a weird/invalid URL. – Mat May 07 '18 at 09:11
  • First try to connect with a ftp client. Many browsers can act as a ftp client, and most OS (including Windows) come with a CLI ftp client. – Serge Ballesta May 07 '18 at 09:11
  • first dont do that : ftplib.FTP('ftp.host.com' , 'user', 'pase') dont add user and Pass in ftplib.FTP that is the first error then , for login use ftp.login('user', 'pass') not like you did , third , for send a command , use cmd = ftp.sendcmd('dir') then print(ftplib.parse257(cmd)) , Thanks – Skiller Dz May 07 '18 at 09:18

1 Answers1

0

Your error is the hostname 'ftp.xx.xxx.xxx.xxx/' doesn't make sense. 'ftp.' indicates it is a host name like 'meta.stackoverflow.com', but then you continue with an IP-address, which has to be just numbers and '.', no characters. This means, your IP-address is interpreted as an hostname, which will not work. Use just the IP-address without 'ftp.':

ftp = ftplib.FTP('xx.xxx.xxx.xxx')

Then you login via the login methode

print(ftp.login("your username", "your password"))

Then you should see a message 'login successful'. If there stands something like 'Login authentication failed' you have wrong username and password.

MegaIng
  • 7,361
  • 1
  • 22
  • 35
  • seems like it fix it, but now i get " raise error_perm(resp) ftplib.error_perm: 530 Login or password incorrect! – Adam May 08 '18 at 09:55
  • i tried a lot of combinations. is see "ftp://maklit@xx.xxx.xxx.xxx/" when i look at preferences of the dir.. what is maklit? user? password? i tried use it as pass and user. lets say the name of my windows user is ETC1. what do i put in login? it tried ftp.login('ETC1', 'maklit') and it did not worked. – Adam May 08 '18 at 10:10
  • need to say i can enter this ftp dir in explorer just by clicking it twice. – Adam May 08 '18 at 10:13
  • @Adam I edited. If you can enter the directory by clicking twice, you once logged in? What did you use? – MegaIng May 08 '18 at 10:16