main.go

package main

import (
"strings"
ftp4go "github.com/shenshouer/ftp4go"
"fmt"
"flag"
"github.com/larspensjo/config"
"time"
) var (
configFile = flag.String("configfile", "config.ini", "General configuration file")
) //配置文件
var TOPIC = make(map[string]string)
var TOPIC1 = make(map[string]string)
//配置文件 func main() { /*读取配置*/
cfg, err1 := config.ReadDefault(*configFile)
if err1 != nil {
restart("读取配置文件失败")
}
if cfg.HasSection("server") {
section, err1 := cfg.SectionOptions("server")
if err1 == nil {
for _, v := range section {
options, err1 := cfg.String("server", v)
if err1 == nil {
TOPIC[v] = options
}
}
}
}
if cfg.HasSection("client") {
section, err1 := cfg.SectionOptions("client")
if err1 == nil {
for _, v := range section {
options, err1 := cfg.String("client", v)
if err1 == nil {
TOPIC1[v] = options
}
}
}
}
/*读取配置*/ /*连接ftp*/
ftpClient := ftp4go.NewFTP()
_, err := ftpClient.Connect(TOPIC["address"], ftp4go.DefaultFtpPort, "")
if err != nil {
restart("连接失败")
}
defer ftpClient.Quit()
_, err = ftpClient.Login(TOPIC["name"], TOPIC["password"], "")
if err != nil {
restart("登陆失败")
}
/*连接ftp*/ /*读取目录*/
var files []string
c1 := make(chan string)
go func(){
if files, err = ftpClient.Nlst(TOPIC["path"]); err != nil {
restart("读取目录失败")
}
c1 <- "读取目录成功"
}()
select {
case res := <-c1:
fmt.Println(res)
case <-time.After(time.Second * ):
restart("读取目录超时")
}
if len(files) == {
restart("无可下载文件")
}
/*读取目录*/ /*执行下载*/
for i := ; i < len(files); i++ {
ch := files[i]
str := strings.Replace(ch, " ", ",", -)
s := strings.Split(str,",")
x := len(s)-
file1 := s[x]
if err = ftpClient.DownloadResumeFile(TOPIC["path"]+"/"+file1, TOPIC1["path"]+file1, false); err == nil{
fmt.Println(TOPIC["path"]+"/"+file1+"--->下载成功")
_, err = ftpClient.Delete(TOPIC["path"]+"/"+file1)
if err == nil {
fmt.Println(TOPIC["path"]+"/"+file1+"--->删除成功")
}else{
restart("删除失败")
break
}
}else{
restart("下载失败")
break
}
}
/*执行下载*/
restart("新的一轮执行")
} func restart(err string){
fmt.Println("重启--------->"+err)
time.Sleep(time.Second * )
main()
}

config.ini

[server]
address = 192.168.1.58
name = test
password =
path = / [client]
path = D:/Ftp/

go ftp通信的更多相关文章

  1. 【转】Android端与Android端利用WIFI进行FTP通信

    原文网址:http://www.cnblogs.com/zhangkai5157/p/4303188.html 一.客户端通信工具类: import java.io.File; import java ...

  2. Android端与Android端利用WIFI进行FTP通信

    一.客户端通信工具类: import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; im ...

  3. Windows10与虚拟机中CentOS-7.2进行ftp通信

    首先Linux的IP地址可以通过以下命令获取: ifconfig Windows10上面IP地址通过下面命令获取 ipconfig 你首先要保证你的主机和Linux虚拟机是可以ping通的(ping都 ...

  4. 使用.net FtpWebRequest 实现FTP常用功能 上传 下载 获取文件列表 移动 切换目录 改名 .

    平时根本没时间搞FTP什么的,现在这个项目需要搞FTP,为什么呢,我给大家说下项目背景,我们的一个应用程序上需要上传图片,但是用户部署程序的服务器上不让上传任何东西,给了我们一个FTP账号和密码,让我 ...

  5. TCP/IP FTP/TFTP

    引言 从一台计算机向另一台计算机传送文件是在连网或互联网环境中最常见的任务.而FTP和TFTP就是这样的协议. 关于文件传输协议FTP? 端口21使用服务TCP [FTP模型] FTP连接? 1.控制 ...

  6. 高可用的Spring FTP上传下载工具类(已解决上传过程常见问题)

    前言 最近在项目中需要和ftp服务器进行交互,在网上找了一下关于ftp上传下载的工具类,大致有两种. 第一种是单例模式的类. 第二种是另外定义一个Service,直接通过Service来实现ftp的上 ...

  7. TCP、UDP通信

    开放系统互连参考模型 (Open System Interconnect 简称OSI) OSI七层模型 1.应用层2.表示层3.会话层4.传输层5.网络层6.数据链路层7.物理层 TCP/IP模型1. ...

  8. http和ftp下载的区别

    HTTP和FTP是两种网络传输协议的缩写,FTP是File Transportation Protocol(文件传输协议)的缩写,而HTTP则是Hyper Text Transportation Pr ...

  9. 下载文件的协议:HTTP、FTP、P2P

    本篇学习笔记以HTTP.FTP.P2P叙述与网上下载文件有关的协议 需要掌握的要点: 下载一个文件可以使用 HTTP 或 FTP,这两种都是集中下载的方式,而 P2P 则换了一种思路,采取非中心化下载 ...

随机推荐

  1. [svc][op]磁盘(结构)容量计算

    磁盘结构和容量计算 fdisk -l显示信息详解 [root@www.linuxidc.com ~]# fdisk -l Disk /dev/sda: bytes heads, sectors/tra ...

  2. Filberder教程

    http://www.cnblogs.com/TankXiao/archive/2012/02/06/2337728.html

  3. [Windows Azure] Building the web role for the Windows Azure Email Service application - 3 of 5

    Building the web role for the Windows Azure Email Service application - 3 of 5. This is the third tu ...

  4. Android 支付宝接口调用

    在近期,公司需要开发一个关于在线支付的模块,所以需要用到第三方支付平台 转载请注明出处:http://blog.csdn.net/ht_android/article/details/45307165 ...

  5. [MyBean说明书]-如何制作BPL插件

    DEMO位置:     samples\simpleConsole\Lib-bpl [步骤]: 1. 首先新建一个BPL工程. 2. 添加一个窗体,实现IPluginForm接口(simpleCons ...

  6. LeetCode: Binary Tree Maximum Path Sum 解题报告

    Binary Tree Maximum Path SumGiven a binary tree, find the maximum path sum. The path may start and e ...

  7. Android 自动化测试

    Python +Android +uiautomator test  在init中定义的方法 uiautomator     该模块是android的一个python包装uiautomator测试框架 ...

  8. [转载]生活在 Emacs 中

    Brian Bilbrey2002 年 8 月 20 日发布 教程简介 本教程讲什么? Emacs 是一个流行的无模式文本编辑器,有许多强大的功能.本教程将教您使用 Emacs 的基础知识.为了让您很 ...

  9. 【iCore4 双核心板_FPGA】例程三:计数器实验——计数器使用

    实验现象: 绿色led闪烁 核心源代码: //--------------------module_counter_ctrl--------------------// module counter_ ...

  10. 【WPF】ListBox嵌套与事件冒泡

    问题:两个ListBox嵌套后,当鼠标位于内部ListBox上,鼠标滚轮事件会被内部ListBox接收,导致外层ListBox不能用鼠标滚轮滑动!现在的需求是该事件要能给外部ListBox处理,即嵌套 ...