Shell---Two commands to create an FTP upload folder

Source: Internet
Author: User

The simple code is as follows: need to upload directory as/root/sk

#!/bin/bash sss= ' find/root/sk-type d-printf '%p\n ' | awk ' {if ($ = = ') next;print "mkdir" $} ' aaa= ' Find/root/sk-type f-printf ' put%p%p \ n ' ftp-nv 127.0.0.1 <<e Of user KABC KABC type binary prompt $sss $aaa quit EOF

Brief description:

Core ideas: 1. Initializing the upload directory structure

2. After initializing the directory, you can upload the file directly using the put command.

3. The main use of FTP's own commands

4. Formatted output (can be viewed as an FTP macro command)

5. Conservative redirect Input stream

The core statement has only two sentences

sss= ' Find/root/sk-type d-printf '%p\n ' | awk ' {if ($ = = ') next;print "mkdir"

The main thing is to use Find to find the directory structure, then format the output, and finally add to the FTP initialization directory structure.

Aaa= ' Find/root/sk-type f-printf ' put%p%p \ n '

The main thing is to use find to find out a non-catalog file, and then format the output, and finally, after initializing the directory, you can use put to upload files directly.

Small white optimized version

The following convenient settings upload directory and remote directory, the empty rewrite into a function

#!/bin/bash updir=/root/sktodir=sksss= ' Find $updir-type d-printf $todir/'%p\n ' | awk ' {if ($ = = ') next;print "mkdir" $} ' aaa= ' Find $updir-type f-printf ' put%p%p \ n ' ftp-nv 127.0.0.1 <<eo F user KABC KABC type binary prompt $sss CD $todir $aaa quit EOF

Upgrade version

#!/bin/bash updir=/root/sk #要上传的文件夹todir =sk #目标文件夹 ip=127.0.0.1 #服务器user =leo #ftp用户名password =1 23456 #ftp密码sss = ' Find $updir-type d-printf $todir/'%p\n ' |  awk ' {if ($ = = ') next;print "mkdir" $} ' aaa= ' Find $updir-type f-printf ' put%p%p \ n ' ftp-nv $ip <<eof user $user $passwordtype binary prompt $sss CD $todir $aaa quit EOF


Shell---Two commands to create an FTP upload folder

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.