FTP script to Shell script &bat script &python script

Source: Internet
Author: User

----Linux Shell script:
#!/bin//home/~/. Bash_profileftpip=127.0. 0.1 ftpuser=ftpuserftppasswd=123456DIR=upfiledumpfile=dy ' Date +_%y%m% d ' 00001_000.tar.gz echo  ${ftpip}echo  ${dumpfile} ftp  -n<<!  /home/ftpuser'get  ${dumpfile}bye!

-----Window Bat Script
@echo Offrem Specify the FTP user nameSetFtpuser=Ftpuserrem specifying the FTP passwordSetftppass=Ftpuserrem specifying the FTP server addressSetftpip=127.0.0.1REM Specifies which directory on the FTP server the file to download is located onSetftpfolder=/REM Specifies which directory the files downloaded from FTP are stored on to this machineSetlocalfolder=d:/Ftp_dataSetftpfile=%temp%/TempFTP.txt>"%ftpfile%"(Echo,%ftpuser%Echo,%ftppass%Echo CD"%ftpfolder%"ls*) Start FTP-v-i-S:"%ftpfile%"%ftpip%REM Specifies enter the resource file nameSet/P Filename=Please enter a resource file name:Setftpfile=%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 script

#!/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"'%HOSTreturnPrint'***connected to host '%s ''%HOSTTry: F.login (user,pwd) except Ftplib.error_perm:print'Error:cannot Login anonymously'f.quit ()returnPrint'* * * logged in as "anonymously"'     Try: F.CWD (Dirn) except Ftplib.error_perm:print'Errorl cannot CD to "%s"'%Dirn f.quit ()returnPrint'* * * Changed to '%s ' folder'%DirnTry: #传一个回调函数给retrbinary () It is called f.retrbinary every time a binary data is received ('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 ()

FTP script to Shell script &bat script &python script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.