遍历目录下文件并上传到ftp
#!/bin/sh #定义ftp上传函数,一次只上传一个文件 ftp_put_file(){ ftp -v -n $ftp_server<<EOF user $ftp_user $ftp_password binary cd $remote_path_ftp lcd $local_path_for_put prompt put $1 bye EOF echo "commit to ftp successfully" } #PUTFILE='taryear_0712.sh' #ftp_put_file $PUTFILE ftp_server='10.1.1.7' ftp_user='uname' ftp_password='password' local_path_for_put='/root/2022/' #定义本地路径,需要上传的文件位于该目录下 remote_path_ftp='/rr/2022/' #定义ftp远端路径,文件上传后所在路径 file_type='*.sh' #定义需要上传的文件格式 put_path_files=$local_path_for_put$file_type put_path=`ls $put_path_files` for file in ${put_path} do putfile=$(basename $file) echo $putfile ftp_put_file $putfile sleep 2 done