0
for ip in ips:  
    ftp = ftplib.FTP(ip)
    ftp.login(username, passwd)

Please help me loop between a few ftp locations to retrieve files from them.

3
  • ftps = [] ftps = ["x.x.x.x","y.y.y.y"] ftp_list =[] for ftpi in ftps: if ftpi == "x.x.x.x": username = "abc" passwd = "1234" ftp = ftplib.FTP(ftpi) ftp.login(username, passwd) ftp_list.append(ftp) elif ftpi == "y.y.y.y": username = "efgh" passwd = "123456" ftp = ftplib.FTP(ftpi) ftp.login(username, passwd) ftp.cwd("/out/qrf/") ftp_list.append(ftp) print ftp_list Commented Sep 4, 2015 at 19:33
  • however, I am not able to make a list of the logged in FTPs.........please help Commented Sep 4, 2015 at 19:34
  • I need to iterate through different FTPs Commented Sep 4, 2015 at 19:36

1 Answer 1

0

You have not provided any error or output. What exactly is your problem. There is a lot of working solutions like: https://stackoverflow.com/a/31342420/1012759 or https://unix.stackexchange.com/questions/88710/ftp-bulk-download-and-rename .

Just write a function and then pass the arguments to it in for loop.

Sign up to request clarification or add additional context in comments.

3 Comments

I am just not able to take different FTP connections in a loop. Just not able to figure out the function. Can you please help me with a simple layout.
ftps = [] ftps = ["x.x.x.x","y.y.y.y"] ftp_list =[] for ftpi in ftps: if ftpi == "x.x.x.x": username = "abc" passwd = "1234" ftp = ftplib.FTP(ftpi) ftp.login(username, passwd) ftp_list.append(ftp) elif ftpi == "y.y.y.y": username = "efgh" passwd = "123456" ftp = ftplib.FTP(ftpi) ftp.login(username, passwd) ftp.cwd("/out/qrf/") ftp_list.append(ftp) print ftp_list
this how I looped between the ftps.......however I am not able to get hold of the files in them

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.