vba上传文件到ftp服务器指定目录下面

vba上传文件到ftp服务器指定目录 +脚本形式

文章目录

    • 1. 测试版本无校验:
    • 2. 测试版本有检验
    • 3. 文件不存在校验版本
    • 4. 文件不存在校验+必填项校验版本

1. 测试版本无校验:

在这里插入图片描述

Sub 按钮1_Click()
Dim i, str1, str2, str3, str4, str5, str6, str7, str8, str9, str10, d
Dim myarray()
On Error Resume Next
Set mysheet1 = ThisWorkbook.Worksheets("sheetName自定义")
Set fs = CreateObject("Scripting.FileSystemObject")'获取本地路径
If mysheet1.Cells(2, 3) <> "" Then
str3 = Replace(Sheet1.Cells(2, 3), "/", "\")
str3 = Trim(str3)
If Right(str3, 1) <> "\" Then
str3 = str3 & "\"
'MsgBox str6
End If
End If'循环扫描文件名,生成一个只有文件名字的字符串
For i = 4 To 100
If mysheet1.Cells(i, 3) <> "" Then
str1 = Replace(Sheet1.Cells(i, 3), "/", "\")
str1 = Trim(str1)
str4 = str3 & str1
str5 = "Echo mput " & Chr(34) & str4 & Chr(34) & " >>ftp.up"
str9 = str9 & " " & str5 'str9所有要上传的文件
End If
Next
'MsgBox str9'上传
Set fsd = CreateObject("Scripting.FileSystemObject")
str10 = str3 & "1.bat" '脚本
str11 = "Echo open ip地址>ftp.up" '远程路径
str12 = "Echo 用户名>>ftp.up" '账号
str13 = "Echo 密码>>ftp.up" '密码Set fid = fsd.CreateTextFile(str10, True) '后面开始写脚本
fid.WriteLine ("@Echo Off ") '开远程
fid.WriteLine (str11)
fid.WriteLine (str12)
fid.WriteLine (str13)
fid.WriteLine ("Echo Cd .\User >>ftp.up")
fid.WriteLine ("Echo binary>>ftp.up")
fid.WriteLine ("Echo prompt >>ftp.up")
fid.WriteLine ("Echo lcd " & Chr(34) & str3 & Chr(34) & ">>ftp.up")
fid.WriteLine (str9)
fid.WriteLine ("Echo bye>>ftp.up")
fid.WriteLine ("FTP -s:ftp.up")
fid.WriteLine ("del ftp.up /q")
fid.Close
str16 = "cmd.exe /c " & str10 '运行脚本
'MsgBox str16
Shell str16MsgBox "传输完成"
End Sub

2. 测试版本有检验

Sub 文件上传ftp服务器()
Dim i, str1, str2, str3, str4, str5, str6, str7, str8, str9, str10, d
Dim myarray(), MyFile As Object
Set MyFile = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set mysheet1 = ThisWorkbook.Worksheets("sheetName自定义")
Set fs = CreateObject("Scripting.FileSystemObject")'获取本地路径
If mysheet1.Cells(2, 3) <> "" Then
str3 = Replace(Sheet1.Cells(2, 3), "/", "\")
str3 = Trim(str3)
If Right(str3, 1) <> "\" Then
str3 = str3 & "\"
'MsgBox str6
End If
End If'循环扫描文件名,生成一个只有文件名字的字符串
For i = 4 To 100
If mysheet1.Cells(i, 3) <> "" Then
str1 = Replace(Sheet1.Cells(i, 3), "/", "\")
str1 = Trim(str1)
str4 = str3 & str1If MyFile.FileExists(str4) = True Then
Else
MsgBox str4 & " 文件不存在"
End Ifstr5 = "Echo mput " & Chr(34) & str4 & Chr(34) & " >>ftp.up"
str9 = str9 & " " & str5 'str9所有要上传的文件
End If
Next
'MsgBox str9'上传
Set fsd = CreateObject("Scripting.FileSystemObject")
str10 = str3 & "1.bat" '脚本
str11 = "Echo open IP地址>ftp.up" '远程路径
str12 = "Echo 用户名>>ftp.up" '账号
str13 = "Echo 口令>>ftp.up" '密码Set fid = fsd.CreateTextFile(str10, True) '后面开始写脚本
fid.WriteLine ("@Echo Off ") '开远程
fid.WriteLine (str11)
fid.WriteLine (str12)
fid.WriteLine (str13)
fid.WriteLine ("Echo Cd .\User >>ftp.up")
fid.WriteLine ("Echo binary>>ftp.up")
fid.WriteLine ("Echo prompt >>ftp.up")
fid.WriteLine ("Echo lcd " & Chr(34) & str3 & Chr(34) & ">>ftp.up")
fid.WriteLine (str9)
fid.WriteLine ("Echo bye>>ftp.up")
fid.WriteLine ("FTP -s:ftp.up")
fid.WriteLine ("del ftp.up /q")
fid.Close
str16 = "cmd.exe /c " & str10 '运行脚本
'MsgBox str16
Shell str16MsgBox "传输完成"
End Sub

3. 文件不存在校验版本

Sub 代码文件上传()Dim i, str1, str2, str3, str4, str5, str6, str7, str8, str9, str10, d
Dim myarray(), MyFile As Object
Set MyFile = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Set mysheet1 = ThisWorkbook.Worksheets("核心_变更解决方案(模版)")
Set fs = CreateObject("Scripting.FileSystemObject")'获取本地路径
If mysheet1.Cells(18, 5) <> "" Then
str3 = Replace(Sheet1.Cells(18, 5), "/", "\")
str3 = Trim(str3)
If Right(str3, 1) <> "\" Then
str3 = str3 & "\"
'MsgBox str6
End If
End If'循环扫描文件名,生成一个只有文件名字的字符串
For i = 20 To 100
If mysheet1.Cells(i, 5) <> "" Then
str1 = Replace(Sheet1.Cells(i, 5), "/", "\")
str1 = Trim(str1)
str4 = str3 & str1If MyFile.FileExists(str4) = True Then
Else
MsgBox str4 & " 文件不存在"
End Ifstr5 = "Echo mput " & Chr(34) & str4 & Chr(34) & " >>ftp.up"
str9 = str9 & " " & str5 'str9所有要上传的文件
End If
Next
'MsgBox str9'上传
Set fsd = CreateObject("Scripting.FileSystemObject")
str10 = str3 & "1.bat" '脚本
str11 = "Echo open IP地址>ftp.up" '远程路径
str12 = "Echo 用户名>>ftp.up" '账号
str13 = "Echo 口令>>ftp.up" '密码Set fid = fsd.CreateTextFile(str10, True) '后面开始写脚本
fid.WriteLine ("@Echo Off ") '开远程
fid.WriteLine (str11)
fid.WriteLine (str12)
fid.WriteLine (str13)
fid.WriteLine ("Echo Cd .\User >>ftp.up")
fid.WriteLine ("Echo binary>>ftp.up")
fid.WriteLine ("Echo prompt >>ftp.up")
fid.WriteLine ("Echo lcd " & Chr(34) & str3 & Chr(34) & ">>ftp.up")
fid.WriteLine (str9)
fid.WriteLine ("Echo bye>>ftp.up")
fid.WriteLine ("FTP -s:ftp.up")
fid.WriteLine ("del ftp.up /q")
fid.Close
str16 = "cmd.exe /c " & str10 '运行脚本
'MsgBox str16
Shell str16MsgBox "传输完成"
End Sub

4. 文件不存在校验+必填项校验版本

在这里插入图片描述

Sub 代码文件上传()' 定义变量 i for循环, str1 文件路径, str3本地路径, str4=str3+str1 文件的绝对路径, str5 批量上传文件列表
'str9 所有要上传的文件, str10=str3+1.bat
Dim i, str1, str3, str4, str5, str9, str10'strname1  key对应的value 这里指系统名, strname 获取模块名称, loginname 登录用户, loginpwd 登录口令
Dim myarray(), MyFile As Object, strname1, strname, loginname, loginpwd'创建了一个FSO对象,然后中用它来读写文本文件,删除文件等
Set MyFile = CreateObject("Scripting.FileSystemObject")'当加上On Error Resume Next语句后,如果后面的程序出现"运行时错误"时,会继续运行,不中断。
On Error Resume Next'定义(变更文件扫描清单)工作表
Set mysheet1 = ThisWorkbook.Worksheets("变更文件扫描清单")
'定义(Sheet1)工作表
Set checklist = ThisWorkbook.Worksheets("Sheet1")'创建了一个FSO对象,然后中用它来读写文本文件,删除文件等
Set fs = CreateObject("Scripting.FileSystemObject")' ----判断指定必填项是否为空 Start----
If mysheet1.Cells(3, 1) = "" Then
MsgBox "系统名称不能为空"
MsgBox "请填写信息完成后,请重新上传!"
Exit Sub
End If
If mysheet1.Cells(3, 2) = "" Then
MsgBox "模块名称不能为空"
MsgBox "请填写信息完成后,请重新上传!"
Exit Sub
End If
If mysheet1.Cells(3, 3) = "" Then
MsgBox "用户名不能为空"
MsgBox "请填写信息完成后,请重新上传!"
Exit Sub
End If
If mysheet1.Cells(3, 4) = "" Then
MsgBox "口令不能为空"
MsgBox "请填写信息完成后,请重新上传!"
Exit Sub
End If
If mysheet1.Cells(5, 1) = "" Then
MsgBox "变更号不能为空"
MsgBox "请填写信息完成后,请重新上传!"
Exit Sub
End If
' ----判断指定必填项是否为空 End----'获取本地路径
If mysheet1.Cells(3, 5) <> "" Then
str3 = Replace(Sheet1.Cells(3, 5), "/", "\")
str3 = Trim(str3)
If Right(str3, 1) <> "\" Then
str3 = str3 & "\"End If
Else: MsgBox "本地路径不能为空"
MsgBox "请填写信息完成后,请重新上传!"
Exit Sub
End If'获取指定表格值
strname = mysheet1.Cells(3, 2)For c = 1 To 25
initkey = checklist.Cells(c, 3)
If initkey = strname Then
strname1 = checklist.Cells(c, 4)
Exit For
End If
Nextloginname = mysheet1.Cells(3, 3)
If strname1 <> loginname Then
MsgBox "模块名与用户名不区配,请核实!!!"
MsgBox "请填写信息完成后,请重新上传!"
Exit Sub
End If'循环扫描文件名,生成一个只有文件名字的字符串
For i = 5 To 100
If mysheet1.Cells(i, 5) <> "" Then
str1 = Replace(Sheet1.Cells(i, 5), "/", "\")
str1 = Trim(str1)
str4 = str3 & str1If MyFile.FileExists(str4) = True Then
Else
MsgBox str4 & " 文件不存在"
End Ifstr5 = "Echo mput " & Chr(34) & str4 & Chr(34) & " >>ftp.up"
str9 = str9 & " " & str5 'str9所有要上传的文件
End If
Next
'MsgBox str9loginpwd = mysheet1.Cells(3, 4)
'上传
Set fsd = CreateObject("Scripting.FileSystemObject")
str10 = str3 & "1.bat" '脚本
str11 = "Echo open IP地址>ftp.up" '远程路径
str12 = "Echo " & loginname & ">>ftp.up" '账号
str13 = "Echo " & loginpwd & ">>ftp.up" '密码wj1 = "set " & Chr(34) & "i=/app/CodeQualityScan/" & loginname & "/" & loginname & "/"
wj2 = "set filesname=" & mysheet1.Cells(5, 1)'---后面开始拼接脚本 Start---
Set fid = fsd.CreateTextFile(str10, True)'开远程
fid.WriteLine ("@Echo Off ")
fid.WriteLine (wj1)
fid.WriteLine (wj2)
fid.WriteLine (str11)
fid.WriteLine (str12)
fid.WriteLine (str13)
fid.WriteLine ("Echo Cd .\User >>ftp.up")
fid.WriteLine ("Echo binary>>ftp.up")
'进入指定ftp目录
fid.WriteLine ("Echo cd %i%>>ftp.up")
'创建指定文件夹
fid.WriteLine ("Echo mkdir %filesname%>>ftp.up")
'进入指定文件夹
fid.WriteLine ("Echo cd %filesname%>>ftp.up")
fid.WriteLine ("Echo prompt >>ftp.up")
fid.WriteLine ("Echo lcd " & Chr(34) & str3 & Chr(34) & ">>ftp.up")
fid.WriteLine (str9)
fid.WriteLine ("Echo bye>>ftp.up")
fid.WriteLine ("FTP -s:ftp.up")
fid.WriteLine ("del ftp.up /q")
fid.Close
'---后面开始拼接脚本 End---
str16 = "cmd.exe /c " & str10 '运行脚本
'MsgBox str16
Shell str16MsgBox "传输完成"
End Sub

1.bat脚本

@Echo Off 
set "i=/app/CodeQualityScan/系统名/用户名/
set filesname=变更号
Echo open IP地址>ftp.up
Echo 用户名>>ftp.up
Echo 口令>>ftp.up
Echo Cd .\User >>ftp.up
Echo binary>>ftp.up
Echo cd %i%>>ftp.up
Echo mkdir %filesname%>>ftp.up
Echo cd %filesname%>>ftp.up
Echo prompt >>ftp.up
Echo lcd "D:\Workspaces\xxxprojectname\">>ftp.upEcho mput "D:\Workspaces\xxxprojectname\ui\js\JsFileName.js" >>ftp.up Echo mput "D:\Workspaces\xxxprojectname\java\JavasadasasdsdsdFileName.java" >>ftp.up Echo mput "D:\Workspaces\xxxprojectname\ui\jsp\JspFileName.jsp" >>ftp.up
Echo bye>>ftp.up
FTP -s:ftp.up
del ftp.up /q

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/523533.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

mysql获取用户权限api_AnalyticDB MySQL服务关联角色

AliyunServiceRoleForAnalyticDBForMySQL介绍角色名称&#xff1a;AliyunServiceRoleForAnalyticDBForMySQL角色权限策略&#xff1a;AliyunServiceRolePolicyForAnalyticDBForMySQL权限说明&#xff1a;{"Version": "1","Statement": [{"A…

分布式存储首选,浪潮商用机器FP5466G2服务器测评分析

戳蓝字“CSDN云计算”关注我们哦&#xff01;如今随着信息时代的到来&#xff0c;以云计算、大数据、人工智能为代表的新晋技术与应用实现了爆发式的增长&#xff0c;随之而来促生了原本存在于各个行业的大量业务应用中PB级&#xff0c;甚至EB级的海量版数据信息&#xff0c;这…

centos7常用工具安装手册

centos7常用工具安装手册 文章目录1. CentOS 7安装 ifconfig2. CentOS 7 上安装vim3. centos7 安装wget4. CentOS7下zip解压和unzip压缩文件5. CentOS 安装rz和sz命令 lrzsz5.1. 首先安装lrzsz5.2. 上传文件&#xff0c;执行命令rz&#xff0c;会跳出文件选择窗口&#xff0c;选…

pipelines mysql_Scrapy爬取豆瓣图书数据并写入MySQL

介绍本篇涉及的内容主要是获取分类下的所有图书数据&#xff0c;并写入MySQL准备Python3.6、Scrapy、Twisted、MySQLdb等演示代码一、创建项目scrapy startproject BookSpider #创建项目scrapy genspider douban book.douban.com #创建豆瓣爬虫二、创建测试类(main.py)from scr…

java 中的原始类型与原始封装类型

Java 提供两种不同的类型&#xff1a;引用类型和原始类型&#xff08;或内置类型&#xff09; 文章目录一、原始与对应的封装类二、引用类型和原始类型的区别:三、总结:比如: Int是java的原始数据类型&#xff0c;Integer是java为int提供的封装类。 一、原始与对应的封装类 J…

独行速众行远,BitTitan携手世纪互联蓝云助力用户数据完美迁移

戳蓝字“CSDN云计算”关注我们哦&#xff01;近日&#xff0c;Saas解决方案提供商BitTitan宣布&#xff0c;将拓展与世纪互联蓝云的合作&#xff0c;双方将在中国的云服务市场上线BitTitan广受欢迎的MigrationWiz用户数据迁移套装方案。BitTitan是一家致力于让IT专业人员通过自…

python字符串的内部函数_Python中字符串中内置函数

字符串内置函数len () 返回字符串长度如&#xff1a;age 31415926print(len(age))输出&#xff1a;长度8string.encode ("utf-8") 指定字符串编码格式如&#xff1a;name "张三"name.encode ("utf-8")string.count (str) 返回str在string中里面…

Kafka精华问答 | 为什么要用Message Queue?

Kafka is a distributed,partitioned,replicated commit logservice。它提供了类似于JMS的特性&#xff0c;但是在设计实现上完全不同&#xff0c;此外它并不是JMS规范的实现。今天就让我们一起来看看关于Kafka 的精华问答吧。1Q&#xff1a;Kafka的主要功能是什么&#xff1f;…

String类、StringBuffer类、StringBuilder类的区别

String是Java中基础且重要的类&#xff0c;并且String也是Immutable类的典型实现&#xff0c;被声明为final class&#xff0c;除了hash这个属性其它属性都声明为final,因为它的不可变性&#xff0c;所以例如拼接字符串时候会产生很多无用的中间对象&#xff0c;如果频繁的进行…

360深度实践:Flink与Storm协议级对比

戳蓝字“CSDN云计算”关注我们哦&#xff01;文 | 张馨予 来源 | 高可用架构作者 张馨予&#xff0c;360 大数据计算平台负责人。北京邮电大学硕士&#xff0c;2015年加入360系统部&#xff0c;一直致力于公司大数据计算平台的易用性、稳定性和性能优化的研发工作。目前主要负…

Spring Cloud Alibaba 雪崩效应和容错解决方案

Spring Cloud Alibaba 雪崩效应和容错解决方案 文章目录1. 雪崩效应1.1. 举个例子&#xff1a;2. 常见的容错方案&#xff1a;2.1.超时&#xff1a;2.2. 限流&#xff1a;2.3. 仓壁模式&#xff1a;2.3.1. 现实中的仓壁模式&#xff1a;2.3.2. 软件中的仓壁模式&#xff1a;2.4…

layui获得列表json数据_golang实战开发之博客功能篇:文章列表的读取与展示和分类筛选展示处理...

前面我们介绍了文章详情页面的展示的逻辑代码实现&#xff0c;这一节&#xff0c;我们将继续讲解文章列表的读取和展示、文章根据分类进行筛选、最新文章、热门文章等的调用处理逻辑。首先&#xff0c;我们先编写文章列表页的前端代码。这里&#xff0c;我们文章采用类似WordPr…

“智企云中享“,首届SAP中国云大会召开

2019 年 6 月 5 日&#xff0c;上海讯— 今日&#xff0c;首届SAP云大会在上海盛大召开。作为SAP云计算家族在中国的首秀&#xff0c;大会全面呈现了SAP云业务的战略、产品、商业场景、浸入式体验。作为体验管理领域的领导者&#xff0c;SAP以覆盖企业运营全价值链的云服务解决…

SpringBoot入门到精通_第7篇 _必知必会总结

接上一篇&#xff1a;SpringBoot入门到精通_第6篇 _必知必会

java对mysql读写权限设置_Java学习笔记——MySQL开放3306接口与设置用户权限

系统Ubuntu16.04 LTS1、开放3306端口查看端口状态:netstat -an|grep 3306tcp 0 0 127.0.0.1:3306 0.0.0.0:* LISTEN目前只有本机可以访问输入指令:sudo vim /etc/mysql/mysql.conf.d/mysqld.cnf如果之前配置过全局配置文件,也可输入指令:su…

容器精华问答 | 如何进行跨机器的Container做Link ?

戳蓝字“CSDN云计算”关注我们哦&#xff01;云计算的发展日新月异&#xff0c;新技术层出不穷&#xff0c;尤其容器技术自2013年Docker容器问世以来一路高歌猛进红遍大江南北&#xff0c;与虚拟机相比&#xff0c;容器更显优势&#xff0c;有着更轻量、更快捷、占用资源更少&a…

Sublime Text3 多行合并为一行

快捷键说明CTRL J多行合并为一行ctrld双击选中关键词或者关键词部分&#xff0c;在输入快捷键关键字就会一个一个选中&#xff0c;就可以同时编辑

安卓psp模拟器哪个好_psp模拟器安卓完美版下载_psp模拟器完美版手机版下载_玩游戏网...

《psp模拟器完美版》App是专业的PSP游戏模拟器&#xff0c;兼容适配任何安卓机型&#xff0c;用户下载于此畅玩PSP游戏&#xff0c;还可自制游戏&#xff0c;能够自由设置多国语言&#xff0c;更改图像、声音、控制、网络等多种选项设置&#xff0c;想玩好游戏&#xff0c;玩打…

腾讯也有“神盾局”?秀出“技术肌肉”就靠TA了……

戳蓝字“CSDN云计算”关注我们哦&#xff01;技术头条&#xff1a;干货、简洁、多维全面。更多云计算精华知识尽在眼前&#xff0c;get要点、solve难题&#xff0c;统统不在话下&#xff01;漫威的超级英雄世界中&#xff0c;“神盾局”一直凭借着不少的先进武器装备&#xff0…

Spring 集成 mybatisPlus

文章目录1. pom.xml2. 实体类3. mapper接口4. applicationContext.xml5. db.properties6. log4j.xml7. mybatis-config.xml8. 测试类9. 控制台输出10. 源码地址1. pom.xml <?xml version"1.0" encoding"UTF-8"?><project xmlns"http://ma…