【问题标题】:How to upload File via FTP_TLS [duplicate]如何通过 FTP_TLS 上传文件 [重复]
【发布时间】:2019-05-02 20:16:57
【问题描述】:

我尝试在 cpanel 中通过 ftp 上传文件,但服务器拒绝连接,我使用 FTP_TLS 似乎已连接,但在这种情况下我不知道如何上传文件

这是我的连接代码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()

结果如下:

*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'

我尝试这样上传示例文件,但结果与之前的注释相同,没有任何改变:

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()

【问题讨论】:

    标签: python ftp


    【解决方案1】:

    你尝试过这样的事情吗?

    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()
    

    确保相应地设置用户名和密码。 详情在这里:https://docs.python.org/3.7/library/ftplib.html#module-ftplib

    【讨论】:

      猜你喜欢
      • 2013-11-24
      • 1970-01-01
      • 2019-08-25
      • 1970-01-01
      • 2020-05-03
      • 1970-01-01
      • 2013-09-01
      • 2013-04-14
      • 1970-01-01
      相关资源
      最近更新 更多