hi all...

i want to upload a file using ftp

path1 = "D:\Python\test"
host = sys.argv[1]
def main():

try:
f = ftplib.FTP(host)
except (socket.error ,socket.gaierror),e:
logging.info("Error: cannot reach '%s',%s" % (host,e))
return
logging.info("***connected to host '%s'***" % host)


try:
f.login(user="root",passwd="aims")
except ftplib.error_perm:
logging.info("Error :cannot login ")
f.quit()
return
logging.info("***logged in ***")

try:
f.storbinary('STOR %s' % path1,open(path1,'rb'))
except ftplib.error_perm:
logging.info("Error:cannot upload a file '%s'" % path1)
os.unlink(path1)
else:
logging.info("***uploaded successfully***" % path1)
f.quit()
return
if __name__ == "__main__":
main()

when i run the script in a cmd i'm getting error like
IOError:Error[13] permission denied :"D:\Python\test"

plz help me:)

put your code in the tags ok.??
once you do, i will help

path1 = "D:\Python\test"
host = sys.argv[1]
def main():

try:
f = ftplib.FTP(host)
except (socket.error ,socket.gaierror),e:
logging.info("Error: cannot reach '%s',%s" % (host,e))
return
logging.info("***connected to host '%s'***" % host)


try:
f.login(user="root",passwd="aims")
except ftplib.error_perm:
logging.info("Error :cannot login ")
f.quit()
return
logging.info("***logged in ***")

try:
f.storbinary('STOR %s' % path1,open(path1,'rb'))
except ftplib.error_perm:
logging.info("Error:cannot upload a file '%s'" % path1)
os.unlink(path1)
else:
logging.info("***uploaded successfully***" % path1)
f.quit()
return
if __name__ == "__main__":
main()

to put code int the code tags. Do this
1. Push the (CODE) tags sign right on the border infront of you.
2. Put your code inside the tags.
3. Then Click on post

path1 = "D:\Python\test"
host = sys.argv[1]
def main():

try:
f = ftplib.FTP(host)
except (socket.error ,socket.gaierror),e:
logging.info("Error: cannot reach '%s',%s" % (host,e))
return
logging.info("***connected to host '%s'***" % host)


try:
f.login(user="root",passwd="aims")
except ftplib.error_perm:
logging.info("Error :cannot login ")
f.quit()
return
logging.info("***logged in ***")

try:
f.storbinary('STOR %s' % path1,open(path1,'rb'))
except ftplib.error_perm:
logging.info("Error:cannot upload a file '%s'" % path1)
os.unlink(path1)
else:
logging.info("***uploaded successfully***" % path1)
f.quit()
return
if __name__ == "__main__":
main()
when i run the script in a cmd i'm getting error like
IOError:Error[13] permission denied :"D:\Python\test"

You get permission denied because the machine you want to login does not have the user as root. I guess you are trying to login into linux box right?

Use the user name and password you use to login to the box. root will not give you the permission.

thanks for a reply......


i'm not using linux ,i m using windows

You must work on your indentation first. All of them are off.
Check out he try's and except. Else's and if's.
They are al not properly indented. Fix that first ok?

i have properly indented ??but i m still getting the error

Post your new indented cde please

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.