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语法及其他知识,所以采用了 ...
随机推荐
- php面试题之一——php核心技术
一.PHP核心技术 1.写出一个能创建多级目录的PHP函数(新浪网技术部) <?php /** * 创建多级目录 * @param $path string 要创建的目录 * @param $m ...
- Log Structured Merge Trees (LSM)
1 概念 LSM = Log Structured Merge Trees 来源于google的bigtable论文. 2 解决问题 传统的数据库如MySql采用B+树存放数据,B ...
- November 20th 2016 Week 47th Sunday
Learn from yesterday, live for today, look to tomorrow. 学习昨天,活在今天,展望明天. There is always room at the ...
- 反射工具类.提供调用getter/setter方法, 访问私有变量, 调用私有方法, 获取泛型类型Class,被AOP过的真实类等工具函数.java
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.Validate; import org.ap ...
- html5 js 游戏的一篇博客 貌似不错
http://blog.csdn.net/lufy_legend/article/details/8888787
- logstash.conf 根据不同地址创建索引
input { http { host => "0.0.0.0" port => 9700 type => "from_ys" }}input ...
- centos下mysqlreport安装和使用
首先查看你的机器是否安装了perl: #perl -v 显示版本号即表示已安装 然后: #yum install perl-DBD-mysql perl-DBI #yum install mysqlr ...
- GeeTest 极验验证
前台Html页面 <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script> ...
- Django提示Unknown database处理方法
cmd.exe运行别人的程序 C:\Python27\Python.exe E:\Django\Guest\Guest\manage.py runserver 提示 django.db.utils.I ...
- c++——对象的构造和析构函数、构造函数的分类及调用
1构造函数和析构函数的概念 有关构造函数 1构造函数定义及调用 1)C++中的类可以定义与类名相同的特殊成员函数,这种与类名相同的成员函数叫做构造函数: 2)构造函数在定义时可以有参数: 3)没有任何 ...