自动编辑ftp上的文件 [英] Automatic editing files on ftp

查看:146
本文介绍了自动编辑ftp上的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,这是一种情况:每天一次,将一个csv文件传送到我的ftp服务器.我需要将此信息导入到我的CRM系统(Salesforce)中.为此,我计划使用skyvia.com及其计划服务.面临的挑战是,csv的列上没有标题,而skyvia无法处理此问题.

So, here's the scenario: once a day, a csv file is delivered to my ftp server. I need to import this information in to my CRM system (Salesforce). For this operation I planned on using skyvia.com, and their scheduling service. The challenge is that the csv comes without header on the columns, and skyvia does not handle this.

所以问题是

  1. 是否可以在ftp服务器上的csv文件中自动插入标题行?我很可能会聘请一名自由职业者来做到这一点,但是我需要知道我的要求. python网络脚本/应用程序能够处理此问题吗?

  1. Is it possible to automatically insert a header row in csv files on ftp server? I will most likely hire a freelancer to do this, but i need to know what I am asking for. Is a python web script/application able to handle this?

skyvia是否有其他替代方法可以处理不带列标题的导入csv?

Is there any alternative to skyvia that will handle import csv without column headers?

是否有其他解决方案可以处理此导入操作,而无需编辑csv或使用Skyvia来为Salesforce处理呢?

Is there any other solution to handle this import operation, without editing csv, or using Skyvia, that could handle this for Salesforce?

我有足够的技巧来独自处理一些操作,但我确实知道自己的局限性...

I am techie enough to handle some operations on my own, but I do know my limits...

推荐答案

FTP协议不允许您在文件开头插入一行.

FTP protocol does not allow you to insert a line to a beginning of a file.

您必须下载整个文件,在本地进行编辑,然后重新上传回去.

You would have to download the whole file, edit it locally, and re-upload it back.

赞:

from io import BytesIO
from ftplib import FTP

ftp = FTP(host, user, passwd)

f = BytesIO()
# Write header
f.write(str.encode("header\n"))
path = "/remote/path/file.csv"
# Append original contents
ftp.retrbinary("RETR " + path, f.write)
# Re-upload back
f.seek(0, 0)
ftp.storbinary("STOR " + path, f)

这篇关于自动编辑ftp上的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆