2011年3月22日 星期二

ftp & scp commands via auto-scripts

FTP
(1) Linux type I
[root@HTS099 Downloads]# ftp -vin yyy.yyy.yyy.yyy << EOF
> user [userid] [userpass] [userid]@[ip or hostname]
> binary
> get index.html
> bye
> EOF

Connected to yyy.yyy.yyy.yyy (xxx.xxx.xxx.xxx).
220 Microsoft FTP Service
331 Password required for [userid].
230 User [userid] logged in.
202 ACCT command not implemented.
200 Type set to I.
local: index.html remote: index.html
227 Entering Passive Mode (xxx,xxx,xxx,xxx,23,40).
125 Data connection already open; Transfer starting.
226 Transfer complete.
18893 bytes received in 0.161 secs (117.56 Kbytes/sec)
221

(2) Linux type II
[root@HTS099 Downloads]# { echo "user [userid] [userpass]"
> echo "binary"
> echo "get index.html"
> echo "bye"
> } | ftp -ivn [ip or hostname]

Connected to yyy.yyy.yyy.yyy (xxx.xxx.xxx.xxx).
220 Microsoft FTP Service
331 Password required for [userid].
230 User [userid] logged in.
202 ACCT command not implemented.
200 Type set to I.
local: index.html remote: index.html
227 Entering Passive Mode (xxx,xxx,xxx,xxx,23,40).
125 Data connection already open; Transfer starting.
226 Transfer complete.
18893 bytes received in 0.161 secs (117.56 Kbytes/sec)
221

(3) Linux type III
[root@HTS099 Downloads]# vi ~/.netrc
    machine [IP or hostname] login [userid] password [userpass]
macdef init
binary
get index.html
bye

#最後一行,記得留空白行,不然ftp時可能會出現錯誤
Connected to cab.org.tw (203.69.42.82).
220 Microsoft FTP Service
Macro definition missing null line terminator.

[root@HTS099 Downloads]# chmod 600 ~/.netrc
#這裡如果沒改permission,ftp時會出現錯誤
Connected to cab.org.tw (203.69.42.82).
220 Microsoft FTP Service
Error - .netrc file not correct permissions.
Remove password or correct mode (should be 600).

[root@HTS099 Downloads]# ftp cab.org.tw #這裡如果敲錯,就會問你ID跟密碼
Connected to yyy.yyy.yyy.yyy (xxx.xxx.xxx.xxx).
220 Microsoft FTP Service
331 Password required for [userid].
230 User [userid] logged in.
202 ACCT command not implemented.
200 Type set to I.
local: index.html remote: index.html
227 Entering Passive Mode (xxx,xxx,xxx,xxx,23,40).
125 Data connection already open; Transfer starting.
226 Transfer complete.
18893 bytes received in 0.161 secs (117.56 Kbytes/sec)
221

(4) Windows type
C:\Documents and Settings\Administrator>type cab.txt
open yyy.yyy.yyy.yyy
user #user在遇到windows的FTP SERVER時,要省略,不然無法成功
[userid]
[userpass]
binary
get index.html
bye
C:\Documents and Settings\Administrator>ftp -i -i -s:"cab.txt"
ftp> open yyy.yyy.yyy.yyy
Connected to yyy.yyy.yyy.yyy.
220 Microsoft FTP Service
User (yyy.yyy.yyy.yyy:(none)):
331 Password required for [userid].

230 User [userid] logged in.
ftp> binary
200 Type set to I.
ftp> get index.html
200 PORT command successful.
150 Opening BINARY mode data connection for index.html(18893 bytes).
226 Transfer complete.
ftp: 18893 bytes received in 0.22Seconds 86.67Kbytes/sec.
ftp> bye
221

#完整BATCH檔建議如下:get_xxx.bat
ECHO Ftp ready to download data
ftp -i -i -s:"cab.txt" >> mlog.log
move *.log "C:\mlog\"

SCP
shell>cat get_xxx.sh
#!/usr/bin/expect

expect -c "
#spawn ssh -L 1234:172.10.10.1:22 guest@10.1.1.2
spawn scp guest@xxx.xxx.xxx:/index.html
set timeout 1800
expect
{
\"password:\" {send \"[password for guest]\r\";}
}
expect eof;"

沒有留言:

張貼留言

文章分類