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