This question is now answered. The problem was that I defined another function open(arg) which took exactely one argument. After changing the name of that function, everything worked fine.
Thank you for your time everyone who read this.
Question
I am trying to upload a file to an ftp server with python using the ftplib.
This is what i have:
def ftp(cmd):
cmd = cmd.split(' ')
try: cmd[3]
except: return 'host user password file (ftpdir)'
try: session = ftplib.FTP(cmd[0],cmd[1],cmd[2])
except: return 'wrong credentials/host'
try: file = open(cmd[3], 'rb')
except: return 'unable to reach file'
try: cmd[4]
except: pass
else:
if cmd[4] !='':
ftplib.FTP.cwd(ftpdir)
name = file.split('\\')[-1]
session.storbinary('STOR ' + name, file) # send the file
file.close() # close file and FTP
session.quit()
I give the function a command in the form of 'host user password file ftpdir' where ftpdir is not required. The error I get is this one:
Traceback (most recent call last):
...some lines of referring...
File "C:\somedir\somefile.py", line 155, in ftp
file = open(cmd[3],'rb')
TypeError: open() takes exactly 1 argument (2 given)
If i try the command "file = open(cmd[3], 'rb')" with a given 'cmd' as entry in a python shell it works fine.
Solution
This question is now answered. The problem was that I defined another function open(arg) which took exactely one argument. After changing the name of that function, everything worked fine.
Thank you for your time everyone who read this.