• FTP 脚本 to Shell脚本&bat脚本&python脚本


    ---- linux Shell 脚本:
    #!/bin/bash
    cd /home/ftpuser
    source ~/.bash_profile
    FTPIP=127.0.0.1
    ftpUser=ftpuser
    ftpPasswd=123456
    DIR=upfile
    DUMPFILE=DY`date +_%Y%m%d`00001_000.tar.gz
     
    echo  ${FTPIP}
    echo  ${DUMPFILE}
     
    ftp  -n<<!
    open ${FTPIP}
    user ${ftpUser} ${ftpPasswd}
    prom
    bin
    cd ${DIR}
    lcd /home/ftpuser'
    get  ${DUMPFILE}
    bye
    !
     
    -----  Window  bat脚本
    @echo off
    rem 指定FTP用户名
    set ftpUser=ftpuser
    rem 指定FTP密码
    set ftpPass=ftpuser
    rem 指定FTP服务器地址
    set ftpIP=127.0.0.1
    rem 指定待下载的文件位于FTP服务器的哪个目录
    set ftpFolder=/
    rem 指定从FTP下载下来的文件存放到本机哪个目录
    set LocalFolder=D:/FTP_DATA
     
    set ftpFile=%temp%/TempFTP.txt
    >"%ftpFile%" (
      echo,%ftpUser%
      echo,%ftpPass%
      echo cd "%ftpFolder%"
        ls  *
    )   
    start ftp -v -i -s:"%ftpFile%" %ftpIP%
     
    rem 指定请输入资源文件名称
    set /p filename=请输入资源文件名称:
     
    set ftpFile=%temp%/TempFTP.txt
    >"%ftpFile%" (
      echo,%ftpUser%
      echo,%ftpPass%
      echo cd "%ftpFolder%"
      echo lcd "%LocalFolder%"
      echo bin
      echo mget %filename%
      echo bye
    )   
    start ftp -v -i -s:"%ftpFile%" %ftpIP%
     

    --- Python 脚本

    #!/usr/bin/python 
    # -*- coding: utf-8 -*- 
    import ftplib 
    import os 
    import socket 
    
    HOST = '127.0.0.1' 
    DIRN = '/home/ftpuser' 
    FILE = 'rinetd.tar.gz' 
    USER = 'ftpuser'
    PWD= '123456'
    
    def main(): 
        try: 
            f = ftplib.FTP(HOST) 
        except (socket.error, socket.gaierror): 
            print 'ERROR:cannot reach " %s"' % HOST 
            return 
        print '***Connected to host "%s"' % HOST 
    
        try: 
            f.login(USER,PWD) 
        except ftplib.error_perm: 
            print 'ERROR: cannot login anonymously' 
            f.quit() 
            return 
        print '*** Logged in as "anonymously"' 
        try: 
            f.cwd(DIRN) 
        except ftplib.error_perm: 
            print 'ERRORL cannot CD to "%s"' % DIRN 
            f.quit() 
            return 
        print '*** Changed to "%s" folder' % DIRN 
        try: 
            #传一个回调函数给retrbinary() 它在每接收一个二进制数据时都会被调用 
            f.retrbinary('RETR %s' % FILE, open(FILE, 'wb').write) 
        except ftplib.error_perm: 
            print 'ERROR: cannot read file "%s"' % FILE 
            os.unlink(FILE) 
        else: 
            print '*** Downloaded "%s" to CWD' % FILE 
        f.quit() 
        return 
    
    if __name__ == '__main__': 
        main()
     
     
     
     
  • 相关阅读:
    0.3 CMD常用命令!以及用CMD显得自己高大上
    1.0 配置JAVA环境和Maven环境(W10注意点)
    2.1 Oracle之DML的SQL语句之单表查询以及函数
    hBase
    2.0 flume、sqoop、oozie/Azkaban
    Hive
    MapReduce和yarn
    HDFS
    1.0 Hadoop的介绍、搭建、环境
    asp.net core系列 43 Web应用 Session分布式存储(in memory与Redis)
  • 原文地址:https://www.cnblogs.com/illusioned/p/7352152.html
Copyright © 2020-2023  润新知