gpt4 book ai didi

Python脚本通过FTP上传文件

转载 作者:IT老高 更新时间:2023-10-28 20:21:55 24 4
gpt4 key购买 nike

我想编写一个脚本来将文件上传到 FTP。

登录系统如何工作?我正在寻找这样的东西:

ftp.login=(mylogin)
ftp.pass=(mypass)

以及任何其他登录凭据。

最佳答案

使用 ftplib ,你可以这样写:

import ftplib
session = ftplib.FTP('server.address.com','USERNAME','PASSWORD')
file = open('kitten.jpg','rb') # file to send
session.storbinary('STOR kitten.jpg', file) # send the file
file.close() # close file and FTP
session.quit()

如果您的 FTP 主机需要 TLS,请改用 ftplib.FTP_TLS


要检索它,您可以使用 urllib.retrieve :

import urllib 

urllib.urlretrieve('ftp://server/path/to/file', 'file')

编辑:

要查找当前目录,请使用 FTP.pwd() :

FTP.pwd(): Return the pathname of the current directory on the server.

要更改目录,请使用 FTP.cwd(pathname) :

FTP.cwd(pathname): Set the current directory on the server.

关于Python脚本通过FTP上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12613797/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com