顯示具有 ftp 標籤的文章。 顯示所有文章
顯示具有 ftp 標籤的文章。 顯示所有文章

2010年4月22日 星期四

How to use ftp in a shell script

公司內部在用的備份機制原本用wput來上傳的
但無奈換個ftp server後,就一直無法順利上傳
研判應該是wput無法針對新版的ftp server正確使用PASV模式
於是只好改用shell script直接上傳
下面的資料摘自How to use ftp in a shell script


Example (non-working) script

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

ftp $HOST <<END_SCRIPT
user $USER
$PASSWD
put $FILE
quit
END_SCRIPT
exit 0

The above script will just hang if run in the foreground (in an xterm), or if run in the background (from a cron job), it will fail to perform the work of transferring file.txt.

/dev/tty names a strange, magic device. Each process (more strictly each process group) has a different /dev/tty, and you can not naively make ftp clients read the password from some non-magic, yet convenient source, like a "here document". When run in an xterm, the script above appears to hang because it reads the password from /dev/tty. The xterm constitutes the script's /dev/tty, so the script waits for keyboard input.

Example Working Script

#!/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

公司內部在用的備份機制原本用wput來上傳的
但無奈換個ftp server後,就一直無法順利上傳
研判應該是wput無法針對新版的ftp server正確使用PASV模式
於是只好改用shell script直接上傳
下面的資料摘自How to use ftp in a shell script


Example (non-working) script

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

ftp $HOST <<END_SCRIPT
user $USER
$PASSWD
put $FILE
quit
END_SCRIPT
exit 0

The above script will just hang if run in the foreground (in an xterm), or if run in the background (from a cron job), it will fail to perform the work of transferring file.txt.

/dev/tty names a strange, magic device. Each process (more strictly each process group) has a different /dev/tty, and you can not naively make ftp clients read the password from some non-magic, yet convenient source, like a "here document". When run in an xterm, the script above appears to hang because it reads the password from /dev/tty. The xterm constitutes the script's /dev/tty, so the script waits for keyboard input.

Example Working Script

#!/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

2009年5月5日 星期二

pure-ftpd + mysql + web_manage

之前己經建置過了,但沒仔細記錄
這次就好好的記錄起來吧~~
參考了很多地方...但總是有缺了一些狀況的說明...
首先先去下載二個檔案
1.pure-ftpd-1.0.22.tar.gz
2.pure-ftpd_user_manage-2.1.tar.tgz

然後就是一連串的安裝過程了...


首先安裝 pure-ftpd-1.0.22.tar.gz
解開後,到目錄下執行
./configure \
--prefix=/usr/local/pureftpd \
--with-mysql \
--with-paranoidmsg \
--with-shadow \
--with-welcomemsg \
--with-uploadscript \
--with-quotas \
--with-cookie \
--with-virtualhosts \
--with-virtualchroot \
--with-diraliases \
--with-sysquotas \
--with-ratios \
--with-ftpwho \
--with-throttling

#make
#make install
#cd configuration-file
#chmod u+x pure-config.pl
#cp pure-config.pl /usr/local/pureftpd/sbin/
#cp pure-ftpd.conf /etc/pureftpd/

到這裡算是做好pure-ftpd的準備工作
======================================================================
若遇到
configure: error: libmysqlclient is needed for MySQL support

則先安裝mysql-devel,即可解決這問題
(yum install mysql-devel)
以及
將/usr/lib64/mysql/内的libmysqlclient.so.15.0.0做個軟連結到/usr/lib下即可
PHP預設是去的 /usr/lib/搜尋的,所以會找不到

上面的資訊來自: E点废墟(www.xok.la) 详细出处参考:http://xok.la/2008/08/configure_error_cannot_find_libmysqlclient_under.html

======================================================================
接下來安裝 pure-ftpd_user_manage-2.1.tar.tgz
解開它
tar -xvzf pure-ftpd_user_manage-2.1.tar.tgz
然後從網頁去做設定
http://xxxxxxx/pure-ftpd_user_manage/install.php
照著它的步驟一步一步設定好

然後將它最後產生的pureftpd-mysql設定檔複製起來
將它存到 /etc/pureftpd/pureftpd-mysql.conf
(記得將install.php刪除)
接下來修改
/etc/pureftpd/pure-ftpd.conf

# MySQL configuration file (see README.MySQL)
MySQLConfigFile /etc/pureftpd/pureftpd-mysql.conf

# Minimum UID for an authenticated user to log in.
MinUID 100
------->這個要注意一下,利用mysql設定帳號時,選登入的身份時
所選的UID記得要比這個數字高才可以登入

======================================================================
然後...就是執行程式了
依照剛才拷貝的pure-config.pl以及pure-ftpd.conf的路徑
/usr/local/pureftpd/sbin/pure-config.pl /etc/pureftpd/pure-ftpd.conf
這樣即可順利開啟起來

之前己經建置過了,但沒仔細記錄
這次就好好的記錄起來吧~~
參考了很多地方...但總是有缺了一些狀況的說明...
首先先去下載二個檔案
1.pure-ftpd-1.0.22.tar.gz
2.pure-ftpd_user_manage-2.1.tar.tgz

然後就是一連串的安裝過程了...


首先安裝 pure-ftpd-1.0.22.tar.gz
解開後,到目錄下執行
./configure \
--prefix=/usr/local/pureftpd \
--with-mysql \
--with-paranoidmsg \
--with-shadow \
--with-welcomemsg \
--with-uploadscript \
--with-quotas \
--with-cookie \
--with-virtualhosts \
--with-virtualchroot \
--with-diraliases \
--with-sysquotas \
--with-ratios \
--with-ftpwho \
--with-throttling

#make
#make install
#cd configuration-file
#chmod u+x pure-config.pl
#cp pure-config.pl /usr/local/pureftpd/sbin/
#cp pure-ftpd.conf /etc/pureftpd/

到這裡算是做好pure-ftpd的準備工作
======================================================================
若遇到
configure: error: libmysqlclient is needed for MySQL support

則先安裝mysql-devel,即可解決這問題
(yum install mysql-devel)
以及
將/usr/lib64/mysql/内的libmysqlclient.so.15.0.0做個軟連結到/usr/lib下即可
PHP預設是去的 /usr/lib/搜尋的,所以會找不到

上面的資訊來自: E点废墟(www.xok.la) 详细出处参考:http://xok.la/2008/08/configure_error_cannot_find_libmysqlclient_under.html

======================================================================
接下來安裝 pure-ftpd_user_manage-2.1.tar.tgz
解開它
tar -xvzf pure-ftpd_user_manage-2.1.tar.tgz
然後從網頁去做設定
http://xxxxxxx/pure-ftpd_user_manage/install.php
照著它的步驟一步一步設定好

然後將它最後產生的pureftpd-mysql設定檔複製起來
將它存到 /etc/pureftpd/pureftpd-mysql.conf
(記得將install.php刪除)
接下來修改
/etc/pureftpd/pure-ftpd.conf

# MySQL configuration file (see README.MySQL)
MySQLConfigFile /etc/pureftpd/pureftpd-mysql.conf

# Minimum UID for an authenticated user to log in.
MinUID 100
------->這個要注意一下,利用mysql設定帳號時,選登入的身份時
所選的UID記得要比這個數字高才可以登入

======================================================================
然後...就是執行程式了
依照剛才拷貝的pure-config.pl以及pure-ftpd.conf的路徑
/usr/local/pureftpd/sbin/pure-config.pl /etc/pureftpd/pure-ftpd.conf
這樣即可順利開啟起來