I am writing simple Python program to upload CSV to FTP server. I am able to connect to the FTP server when I connect using WinSCP. But when I run my Python program, it ends with the below error.
ftp.connect(host, 22)
File "C:\Python\Python39\lib\ftplib.py", line 162, in connect
self.welcome = self.getresp()
File "C:\Python\Python39\lib\ftplib.py", line 244, in getresp
resp = self.getmultiline()
File "C:\Python\Python39\lib\ftplib.py", line 234, in getmultiline
nextline = self.getline()
File "C:\Python\Python39\lib\ftplib.py", line 218, in getline
raise EOFError
EOFError
host = "sftp.xx.com"
username = "username"
password = "passwrd"
ftp = FTP()
ftp.connect(host, 22)
print("..")
login_status = ftp.login(username,password)
print(login_status)
# change directory to upload
ftp.cwd('/content/remotedir')
# print the content of directory
print(ftp.dir())
fp = open("C:\sample.csv", 'rb')
# upload file
ftp.storbinary('STOR %s' % os.path.basename("C:\sample.csv"), fp, 1024)
fp.close()
print(ftp.dir())