歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> SHELL編程 >> Linux下使用shell實現上傳linux下某個目錄下所有文件到ftp

Linux下使用shell實現上傳linux下某個目錄下所有文件到ftp

日期:2017/3/2 17:13:19   编辑:SHELL編程

首先我們需要搞清楚單個文件怎麼上傳,把這個單文件上傳到ftp上的實現命名為一個:upload_to_ftp_command.sh

之後,需要弄清楚怎麼實現遍歷一個目錄下的所有文件的,把這個遍歷某個目錄下的文件實現命名為:foeach_directory_and_uploadfile_to_ftp.sh。

upload_to_ftp_command.sh

#!/bin/bash
FTILE_NAME=$1
ftp -n <<- EOF
open 10.70.41.126
user jy new.abc$
cd /Temp/a_datang/s1mme1031
bin
put $FTILE_NAME
bye
EOF

foeach_directory_and_uploadfile_to_ftp.sh

#!/bin/bash

for file in ./*
do if test -f $file then echo $file ' is file' ./upload_to_ftp_command.sh $file fi if test -d $file then echo $file ' is directory' fi done

調用foeach_directory_and_uploadfile_to_ftp.sh:

$ ./foeach_directory_and_uploadfile_to_ftp.sh 
./000000_0  is file
./000001_0  is file
./000002_0  is file
./000003_0  is file
./000004_0  is file
./000005_0  is file
./000006_0  is file
./000007_0  is file
./000008_0  is file
./000009_0  is file
./000010_0  is file
./000011_0  is file
./000012_0  is file
./000013_0  is file
./000014_0  is file
./000015_0  is file
./000016_0  is file
./000017_0  is file
./000018_0  is file
./000019_0  is file
./000020_0  is file
./000021_0  is file
./000022_0  is file
./upload_to_ftp_command.sh  is file
./foeach_directory_and_uploadfile_to_ftp.sh  is file
Copyright © Linux教程網 All Rights Reserved