How to upload (FTP) files to server in a bash scri

2019-01-12 20:19发布

I'm trying to write a bash script that uploads a file to a server. How can I achieve this? Is a bash script the right thing to use for this?

标签: bash ftp
11条回答
干净又极端
2楼-- · 2019-01-12 21:02

Working Example to Put Your File on Root ...........see its very simple

#!/bin/sh
HOST='ftp.users.qwest.net'
USER='yourid'
PASSWD='yourpw'
FILE='file.txt'

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
put $FILE
quit
END_SCRIPT
exit 0
查看更多
小情绪 Triste *
3楼-- · 2019-01-12 21:06

Install ncftpput and ncftpget. They're usually part of the same package.

查看更多
我命由我不由天
4楼-- · 2019-01-12 21:08

command in one line:

ftp -in -u ftp://username:password@servername/path/to/ localfile
查看更多
beautiful°
5楼-- · 2019-01-12 21:15

use this to upload a file to a remote location

#!/bin/bash
#$1 is the file name
#usage:this_script <filename>
HOST='your host'
USER="your user"
PASSWD="pass"
FILE="abc.php"
REMOTEPATH='/html'

ftp -n $HOST <<END_SCRIPT
quote USER $USER
quote PASS $PASSWD
cd $REMOTEPATH
put $FILE 
quit
END_SCRIPT
exit 0
查看更多
\"骚年 ilove
6楼-- · 2019-01-12 21:15

No need to complicate stuff - this should work:

#/bin/bash
echo "
 verbose
 open ftp.mydomain.net
 user myusername mypassword
 ascii
 put textfile1
 put textfile2
 bin
 put binaryfile1
 put binaryfile2
 bye
" | ftp -n > ftp_$$.log

or you can use mput if you have many files ...

查看更多
做个烂人
7楼-- · 2019-01-12 21:16
#/bin/bash
# $1 is the file name
# usage: this_script  <filename>
IP_address="xx.xxx.xx.xx"
username="username"
domain=my.ftp.domain
password=password

echo "
 verbose
 open $IP_address
 USER $username $password
 put $1
 bye
" | ftp -n > ftp_$$.log
查看更多
登录 后发表回答