无法在Python中上载到FTP服务器

无法在Python中上载到FTP服务器,python,ftp,Python,Ftp,我正在尝试通过FTP上传文件,我有以下代码: def ftp_upload(localfile, remotefile): fp = open(localfile, 'rb') ftp.storbinary('STOR %s' % os.path.basename(localfile), 'rb', 1024) fp.close() print ("after upload " + localfile + " to " + remotefile) 代码执行时不会

我正在尝试通过FTP上传文件,我有以下代码:

def ftp_upload(localfile, remotefile):
    fp = open(localfile, 'rb')
    ftp.storbinary('STOR %s' % os.path.basename(localfile), 'rb', 1024)
    fp.close()
    print ("after upload " + localfile + " to " + remotefile)
代码执行时不会出错,但不会上载任何文件。

为什么代码不起作用 您正在使用“rb”作为文件指针,您应该使用打开的文件指针

示例代码[(稍微修改)]
你是不是忘记了文章中的缩进,还是真正的代码中的缩进?如果是这样,函数每次都返回None,并且函数不执行下面的代码。
def placeFile():
    filename = 'exampleFile.txt'
    open_file = open(filename, 'rb')
    ftp.storbinary('STOR '+filename, open_file)
    ftp.quit()
placeFile()