草庐IT

ftp_pasv

全部标签

python - 从 FTP 检索文件时如何指定本地目标文件夹

当前代码会将远程XML文件下载到该程序所在的目录。如何指定另一个本地目录作为目的地?如果这里有什么奇怪的代码也请指出。:)importftplibimportosimportosimportsocketHOST='ftp.server.com'DIRN='DirectoryInFTPServer'filematch='*.xml'username='username'password='password'defmain():try:f=ftplib.FTP(HOST)except(socket.error,socket.gaierror),e:print'ERROR:cannotrea

python - 通过 FTP 确定列表是 Python 中的目录还是文件

Python有一个标准库模块ftplib来运行FTP通信。它有两种获取目录内容列表的方法。其中之一,FTP.nlst(),将返回一个目录的内容列表,给定一个目录名作为参数。(如果给定文件名,它将返回文件名。)这是列出目录内容的可靠方法,但不会给出列表中的每一项是文件还是目录的任何指示。另一种方法是FTP.dir(),它以字符串格式列出作为参数给出的目录的目录内容(或文件属性,给定文件名)。根据apreviousquestiononStackOverflow,解析dir()的结果可能很脆弱(不同的服务器可能返回不同的字符串)。不过,我正在寻找某种方法来通过FTP仅列出另一个目录中包含的目

python - 使用 ftplib 在 Python 中设置 FTP 连接超时

我正在尝试设置FTP连接的超时时间:classftplib.FTP([host[,user[,passwd[,acct[,timeout]]]]])ReturnanewinstanceoftheFTPclass.Whenhostisgiven,themethodcallconnect(host)ismade.Whenuserisgiven,additionallythemethodcalllogin(user,passwd,acct)ismade(wherepasswdandacctdefaulttotheemptystringwhennotgiven).Theoptionaltime

Python 错误捕获和 FTP

尝试获取Python中FTP库的句柄。:)到此为止。fromftplibimportFTPserver='127.0.0.1'port='57422'print'FTPClient('+server+')port:'+porttry:ftp=FTP()ftp.connect(server,port,3)print'Connected!Welcomemsgis\"'+ftp.getwelcome()+'\"'ftp.cwd('\\')x='1'currentDir=''except://***WhatdoIputhere?***http://docs.python.org/library

python - 使用 Python 通过流将数据从 FTP 服务器传输到 S3 时出现问题

我希望将文件夹的内容从ftp服务器传输到s3中的存储桶,而无需写入磁盘。目前,s3正在获取文件夹中所有文件的名称,但没有实际数据。文件夹中的每个文件只有几个字节。我不太清楚为什么它没有上传整个文件。fromftplibimportFTPimportioimportboto3s3=boto3.resource('s3')ftp=FTP('ftp.ncbi.nlm.nih.gov')ftp.login()ftp.cwd('pubchem/RDF/descriptor/compound')address='ftp.ncbi.nlm.nih.gov/pubchem/RDF/descriptor

python - 在 Python 中从 FTP 文件夹(文件名有空格)获取最新文件

我有一个要求,我必须从FTP文件夹中提取最新的文件,问题是文件名有空格并且文件名有特定的模式。下面是我实现的代码:importsysfromftplibimportFTPimportosimportsocketimporttimeimportpandasaspdimportnumpyasnpfromglobimportglobimportdatetimeasdtfrom__future__importwith_statementftp=FTP('')ftp.login('','')ftp.cwd('')ftp.retrlines('LIST')filematch='*Elig.xlsx

python - Python FTP 应用程序中的代理

我正在用Pythonftplib开发一个FTP客户端。如何为其添加代理支持(我见过的大多数FTP应用程序似乎都有)?我特别考虑SOCKS代理,还有其他类型...FTP、HTTP(甚至可以将HTTP代理与FTP程序一起使用吗?)有什么想法吗? 最佳答案 根据this来源。取决于代理,但常用的方法是ftp到代理,然后使用目标服务器的用户名和密码。例如对于ftp.example.com:Serveraddress:proxyserver(oropenproxyserverfromwithftp)User:anonymous@ftp.exa

python - 在 FTP 服务器上扩展 Python 的 os.walk 功能

如何让os.walk遍历FTP数据库(位于远程服务器上)的目录树?现在代码的结构方式是(提供注释):importfnmatch,os,ftplibdeffind(pattern,startdir=os.curdir):#findfunctiontakingvariablesforbothdesiredfileandthestartingdirectoryfor(thisDir,subsHere,filesHere)inos.walk(startdir):#eachofthevariableschangeasthedirectorytreeiswalkedfornameinsubsHer

python - FTP 库错误 : got more than 8192 bytes

Python在上传大小超过8192字节的文件时失败。而异常(exception)只是“得到超过8192个字节”。是否有上传更大文件的解决方案。try:ftp=ftplib.FTP(str_ftp_server)ftp.login(str_ftp_user,str_ftp_pass)exceptExceptionase:print('Connectingftpserverfailed')returnFalsetry:print('Uploadingfile'+str_param_filename)file_for_ftp_upload=open(str_param_filename,'r

python - 检查 Python FTP 连接

我有一个FTP连接,我正在从中下载许多文件并在中间处理它们。我希望能够检查我的FTP连接是否在两者之间超时。所以代码看起来像这样:conn=FTP(host='blah')conn.connect()foriteminlist_of_items:myfile=open('filename','w')conn.retrbinary('stuff",myfile)###dosomeparsing###如果在###dosomeparsing###行期间超时,我该如何检查我的FTP连接? 最佳答案 发送NOOP命令。这只会检查连接是否仍在进