python 读取csv中的文件,从sftp下载文件
需要从sftp上下载一些图片文件,文件名存放在一个csv文件中。代码如下:
# -*- coding:utf-8 -*-
import paramiko
import csv
import os def sft_download_all(host,port,username,password):
sf = paramiko.Transport((host,port))
sf.connect(username = username,password = password)
sftp = paramiko.SFTPClient.from_transport(sf) csv_reader1=csv.reader(open(r'D:\数据处理\photo.csv',encoding='utf-8'))
for row in csv_reader1:
remote=row[2]
filename=row[1]
localfile='D:\\训练数据\\all\\'+filename
try:
if sftp.stat(remote) and (not os.path.exists(localfile)):
print("download:"+remote)
sftp.get(remote,localfile)
except Exception as e:
print('出错跳过:file='+remote+' exception:',e)
continue
print("全部数据下载完毕!") def sftp_download(host,port,username,password):
sf = paramiko.Transport((host,port))
sf.connect(username = username,password = password)
sftp = paramiko.SFTPClient.from_transport(sf) csv_reader1=csv.reader(open(r'D:\数据处理\系安全带的.csv',encoding='utf-8'))
for row in csv_reader1:
remote=row[4]
filename= os.path.basename(remote)
localfile='D:\\训练数据\\hasbelt\\'+filename
try:
if sftp.stat(remote) and (not os.path.exists(localfile)):
print("download:"+remote)
sftp.get(remote,localfile)
except Exception as e:
print('出错跳过:file='+remote+' exception:',e)
continue
print("通过数据下载完毕!") csv_reader2=csv.reader(open(r'D:\数据处理\没系安全带.csv',encoding='utf-8'))
for row in csv_reader2:
remote=row[4]
filename= os.path.basename(remote)
localfile='D:\\训练数据\\beltno\\'+filename
try:
if sftp.stat(remote) and (not os.path.exists(localfile)):
print("download:"+remote)
sftp.get(remote,localfile)
except Exception as e:
print('出错跳过:file='+remote+' exception:',e)
continue
print("不通过数据下载完毕!")
sf.close() if __name__ == '__main__':
host = '172.16.207.21'#主机
port = 22 #端口
username = 'root' #用户名
password = 'data' #密码
sftp_download(host,port,username,password)#下载
#sft_download_all(host,port,username,password)
python 读取csv中的文件,从sftp下载文件的更多相关文章
- python读取csv,Excel,Txt,Yaml 文件
1.数据 1.Csv login.csv文件: byhy,88888888 ReadCsv.py文件 import csv #导入csv包 class ReadCsv(): def csv(self) ...
- ean13码的生成,python读取csv中数据并处理返回并写入到另一个csv文件中
# -*- coding: utf-8 -*- import math import re import csv import repr def ean_checksum(eancode): &quo ...
- Python读取CSV文件,报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0xa7 in position 727: illegal multibyte sequence
Python读取CSV文件,报错:UnicodeDecodeError: 'gbk' codec can't decode byte 0xa7 in position 727: illegal mul ...
- Python读取excel中的图片
作为Java程序员,Java自然是最主要的编程语言.但是Java适合完成大型项目,对于平时工作中小的工作任务,需要快速完成,易于修改和调试,使用Java显得很繁琐,需要进行类的设计,打成jar包,出现 ...
- 【Python】Python 读取csv的某行或某列数据
Python 读取csv的某行 转载 2016年08月30日 21:01:44 标签: python / csv / 数据 站长用Python写了一个可以提取csv任一列的代码,欢迎使用.Gith ...
- python读取excel中单元格的内容返回的5种类型
(1) 读取单个sheetname的内容. 此部分转自:https://www.cnblogs.com/xxiong1031/p/7069006.html python读取excel中单元格的内容返回 ...
- python读取csv转换为dataframe
前言: 由于在处理结构性数据的时候经常会读取本地形如:.xls.xlsx.csv等的数据.所以今天就花了点时间来总结一下利用python读取csv数据并且转换为dataframe的数据框架.话不多说, ...
- Python 实现批量从不同的Linux服务器下载文件
基于Python实现批量从不同的Linux服务器下载文件 by:授客 QQ:1033553122 实现功能 1 测试环境 1 使用方法 1 1. 编辑配置文件conf/file_for_downl ...
- Python 读取csv文件到excel
朋友问我如何通过python把csv格式的文件另存为xls文件,自己想了想通过读取csv文件然后再保存到xls文件中即可,也许还有其他简单的方法,但这里也为了练习python语法及其他知识,所以采用了 ...
随机推荐
- [转]CentOS7增加或修改SSH端口号
前言:开启某服务或软件的端口,要从该服务或软件监听的端口(多以修改配置文件为主),SeLinux和防火墙(FireWall)的安全策略下手.如果使用阿里云,腾讯等第三方服务器还需要对管理控制台的安全组 ...
- python3+OpenGL环境配置
注:示例系统环境:Windows10 64位 + Anaconda3: 1.首先登录https://www.opengl.org/resources/libraries/glut/,下载下图箭头所指的 ...
- Django template 过滤器
转载自: http://www.lidongkui.com/django-template-filter-table 一.形式:小写 {{ name | lower }} 二.过滤器是可以嵌套的,字符 ...
- FTP response 421 received. Server closed connection
现象: 在springboot的定时器轮询去下载ftp文件时,报以下错误: org.apache.commons.net.ftp.FTPConnectionClosedException: FTP r ...
- sqooq同步mysql tinyint类型到hive的一个诡异问题
sqoop job运行完成之后,发现为tinyint类型的一类始终没有值,经检查发现上游mysql有值,再查看hdfs文件,发现这列被抓换为了boolean类型 搜索一下发现有人碰到过了,以下原文来自 ...
- Linux配置CentOs7.4(网络连接处理)
说明:CentOS 7.0默认安装好之后是没有自动开启网络连接的! 进入登录界面 账号输入root 回车 再输入上面设置的root密码回车 系统登录成功 设置IP地址.网关DNS cd /etc/s ...
- 【转】Android 旋转动画,停止和持续旋转
旋转180度后停止 RotateAnimation rotate; rotate =new RotateAnimation(0f,180f,Animation.RELATIVE_TO_SELF, 0. ...
- F2eTest程序快捷方式安装到桌面
按照http://f2etest.***.com/install页面上介绍的:安装快捷方式到Windows桌面 (Win7)部分的介绍进行安装. 其中第三步的https连接需要在f2etest的c ...
- weblogic之CVE-2018-3246 XXE分析
通过ftp通道将数据传出来.上传1.xml <!DOCTYPE xmlrootname [<!ENTITY % aaa SYSTEM "http://192.168.172.12 ...
- docker 不同版本 添加--insecure-registry
docker 17.0.3 vim /lib/systemd/system/docker.service 然后重启 systemctl daemon-reload , systemctl rest ...