0

i try to upload file via ftp in cpanel but the server refused connection and i used FTP_TLS it seems connected but i don't know how to upload file in this case

this is my connection code in FTP_TLS:

from ftplib import FTP_TLS

ftp=FTP_TLS()
ftp.set_debuglevel(2)
ftp.connect('ftp.EX.com')
ftp.sendcmd('ftp_usr')
ftp.sendcmd('ftp_pass')
ftp.dir()
ftp.close()

and the result is this following note:

*get* '220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------\n'
*get* '220-You are user number 2 of 50 allowed.\n'
*get* '220-Local time is now 00:08. Server port: 21.\n'
*get* '220-This is a private system - No anonymous login\n'
*get* '220-IPv6 connections are also welcome on this server.\n'
*get* '220 You will be disconnected after 15 minutes of inactivity.\n'
*resp* '220---------- Welcome to Pure-FTPd [privsep] [TLS] ----------\n220-You are user number 2 of 50 allowed.\n220-Local time is now 00:08. Server port: 21.\n220-This is a private system - No anonymous login\n220-IPv6 connections are also welcome on this server.\n220 You will be disconnected after 15 minutes of inactivity.'
*cmd* 'ftp_usr'
*put* 'ftp_usr\r\n'

and i try this to upload example file like this but the result is same as previous note and nothing changed :

ftp=FTP_TLS()
ftp.set_debuglevel(2)
ftp.connect('ftp.EX.com')
ftp.sendcmd('ftp_usr')
ftp.sendcmd('ftp_pass')
file = open('imaege.jpg','rb')
ftp.storbinary('STOR image.jpg', file)
ftp.dir()
ftp.close()

1 Answers1

0

Have you tried something like this?

from ftplib import FTP_TLS
ftp = FTP_TLS()
ftp.set_debuglevel(2)
ftp.connect('ftp.EX.com')
ftp.login(user='ftp_usr', passwd='ftp_pass')
print(ftp.getwelcome())
ftp.storbinary('STOR image.jpg', open('image.jpg','rb'))
print(ftp.dir())
ftp.close()

Ensure to set username and password accordingly. Details here: https://docs.python.org/3.7/library/ftplib.html#module-ftplib