0

im new to python and love it but find it hard to find basic guides.. hopefully someone can help!

anyways i managed to connect to ftp but i cannot find how to download a Directory and files..

i have managed to create a script to copy local fiiles beween harddrives but i dont know the path syntax for ftp..

this is what i have for local backup

src = ('E:\\ITCIRCLECONSULT\\')
dst = ('D:\\COPY\\' +
       newFolderName.strftime('%d-%B-%y\\').upper())

i know it will be simple but the simple things are hard to find!

import ftplib
from ftplib import FTP

ftp = FTP('ftp.xxxxxx.com')
ftp.login('username', 'password')
ftp.retrlines('LIST')
ftp.cwd("/public_html")
file_list = []
filenames = ftp.nlst()

           
ftp.close() 

Edit to Add..

I have laid it out the way i want it to work, user inputs data.. Alas, it does not work.

The script skips through the user input and produces an error..

The aim here is to allow the user to input the various information to be called into the ftp carry on before attempting to connect..

any help appreciated.. guidance and tutorage! :)

import ftplib
from ftplib import FTP

ftp_add =  input('ftp address:')
username = input('username:')
password = input('password:')


ftp = FTP(ftp_add)
ftp.login(username, password)
ftp.retrlines('LIST')
ftp.cwd("/public_html")
file_list = []
filenames = ftp.nlst()

           
ftp.close() 
johnashu
  • 2,167
  • 4
  • 19
  • 44
  • `ftp.login(username, password)` seems like it should work. What problem are you having? – Barmar Apr 14 '17 at 00:58
  • i wish to have the user input the username password and ftp address before running the code. if i do this line by line it is fine – johnashu Apr 14 '17 at 00:59
  • when i run the script there is no user input prompt.. – johnashu Apr 14 '17 at 00:59
  • i might add im 100% noob with python.. – johnashu Apr 14 '17 at 01:00
  • I can't see any reason why it wouldn't prompt for input. That's what the `input()` function does. – Barmar Apr 14 '17 at 01:01
  • How are you running the script? – Barmar Apr 14 '17 at 01:02
  • exactly.. im having the exact same problem here with a backup/copy script.. i want to combine the 2 at somepoint but im stumped at the first hurdle lol – johnashu Apr 14 '17 at 01:02
  • http://stackoverflow.com/questions/43402421/user-inputted-directory-to-copy trying to have te user input the source and destination paths before copy sorry.. enter sends the message! – johnashu Apr 14 '17 at 01:03
  • i run the script in the interpereter by copying and pasting the code.. if i incluse all the details in the script it will run.. if i include input it skips it.. if i copy and paste line by line it works fine i still dont know how to execute a script.py file .. im using windows – johnashu Apr 14 '17 at 01:05
  • Just put all the commands in a file and type `python scriptname.py` in the command window. – Barmar Apr 14 '17 at 01:06
  • Do you have this problem with all scripts that use `input()`, or just these backup scripts? – Barmar Apr 14 '17 at 01:07
  • these are the first 2 scripts ive written in python.. i cant run .py files for love nor money for some reason... ive tried in powershelll, command, python,.. – johnashu Apr 14 '17 at 01:11
  • It sounds to me like you have a more general problem with your python installation. Unfortunately, I don't know anything about installing and running Python on Windows. – Barmar Apr 14 '17 at 01:13
  • SyntaxError: unexpected character after line continuation character – johnashu Apr 14 '17 at 01:13
  • yes thats what i thought.. – johnashu Apr 14 '17 at 01:14
  • i have installed nad uninstalled python 2.7 and 3.6 a few times – johnashu Apr 14 '17 at 01:14
  • That error means you have a backslash in an incorrect place. Search for the error message on SO and you'll find other questions that explain it. – Barmar Apr 14 '17 at 01:15
  • its the craziest thing.. i literally uninstalled python.. i erased every trace from the registry, frm the hd, rebooted and reloaded twice.. and still unless i type line by line it wont run.. im totally new to python.. i can code but i cant troubleshoot this lol.. – johnashu Apr 14 '17 at 02:18
  • So what happens if you just type `val = input("Type something:")` into the interpreter? – Barmar Apr 14 '17 at 02:31
  • it asks for a prompt.. i can connect to ftp.. move files.. do alsorts line by line but i cannot run a script – johnashu Apr 14 '17 at 02:35
  • or if i do run a script with "input" it will only ask for input if the last line of the script is an input – johnashu Apr 14 '17 at 02:36

0 Answers0