茫茫網海中的冷日
         
茫茫網海中的冷日
發生過的事,不可能遺忘,只是想不起來而已!
 恭喜您是本站第 1670872 位訪客!  登入  | 註冊
主選單

Google 自訂搜尋

Goole 廣告

隨機相片
FF18_Cosplayer_00090.jpg

授權條款

使用者登入
使用者名稱:

密碼:


忘了密碼?

現在就註冊!

小企鵝開談 : [轉貼]linux ftp shell 命令

發表者 討論內容
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]linux ftp shell 命令
linux ftp shell命令

Linux ftp

1、登錄ftp
代碼:
lftp 用戶名:密碼@ftp地址:傳送端口(默認21)
用法
(1)lftp username:password@127.0.0.1:21 回車
(2)lftp username@127.0.0.1 回車     ##默認21端口 回車後輸入密碼
(3)lftp 127.0.0.1 回車   ##回車後 login 登錄
(4)lftp 回車 --> open 127.0.0.1 --> login 登錄

感覺自己很像孔乙己了,茴香豆的"茴"有幾種寫法阿! ~真暈阿~

2、lftp中文亂碼問題
對於像我這樣的新手,登錄後看到的都是中文亂碼(因為一般本地都是utf-8的編碼),怎麼半呢,用 set 命令來解決
set ftp:charset gbk(或者 gb2312 或 utf-8) ##設置ftp端的編碼格式
set file:charset utf-8 (...同上) ##設置本地編碼格式

附:set命令的技巧 (1)輸入set 查看已經設置好的命令 (2)set -a 查看所有可以設置的命令清晰網

3、查找ftp端文件
ls *.txt ##查找當前目錄下的所有txt文件
ls ./123/ ##列出123目錄下所有文件
find . -name "*.txt"   ##遞歸查找站點上所有的txt文件
find ./xx -name "*.txt" ##查找xx目錄下所有的txt文件

附1: ls第二次讀取的是本地緩存,可以用 rels 代替 ls 或者catch off / catch on 來開關catch,catch flush清空本地catch
附2: 瀏覽本地目錄的命令可用!ls, 如 !ls /usr/local/bin/

4、下載文件
下載文件之前要先設置好本地的目錄,用來存放下載的文件
lcd /home/123/web   ##設置本地存放目錄 默認為 /home/usr

get 123.txt     ##下載123.txt文件到 /home/123/web 中
get -c 123.txt ##斷點續傳下載
mget *.txt     ##批量下載所有txt文件
mget -c *.txt ##斷點續傳
mget -c ./123/aaa/*.txt   ##斷點續傳、批量下載ftp端aaa目錄下的所有txt文件

pget -c -n 10 file.dat

##以最多10個線程以允許斷點續傳的方式下載file.dat
##可以通過設置 set pget:default-n 5 的值而使用默認值。
mirror aaa/

##將aaa目錄整個的下載下來,子目錄也會自動複製 本地自動建立目錄

5、上傳文件
put 123.txt     ##同下載
mput *.txt     ##同下載

mirror -R aaa/ ##同下載

6、設置被動/非被動模式
set ftp:passive-mode 1 ## 1 被動 0非主動

多任務處理
ctrl+z ##將當前進行的任務移交後台處理
wait   ##將後台處理任務調至前台查看
jobs   ##查看後台進行的任務列表
kill all 或者 job_no ##刪除所有任務 或 指定的任務

##將任務加入任務列表
queue get 123.txt
queue put 234.txt
queue mirror aaa/

queue ##查看任務列表
jobs   ##查看後台任務列表

queue start ##開始任務列表
queue stop ##停止任務列表

其他命令清晰網
alias []

定義別名
alias less more
alias reconnect "close; cd ."

直接輸入 alias 即可看到目前定義了那些別名。如果只輸入 alias name 的話, 則是取消 name 這個別名。
bookmark SUBCMD

設定書籤, 可將目前站台及所在目錄設成書籤, 下次可直接進來, 不用再 cd 來 cd 去的
bookmark add name 用來新增名稱為 name 的書籤
bookmark del name 刪除名稱為 name 的書籤
bookmark list 顯示目前有設定那些書籤(另外直接打 bookmark 和 bookmark list 的結果一樣)
bookmark edit 呼叫編輯器修改書籤 (~/.lftp/bookmarks)

cd

切換遠端目錄
cache SUBCMD

管理 lftp 的 cache
rels []

從 cache 中顯示遠端檔案列表
rels 則不會從 cache 中讀取
recls opts [path/]pattern

從 cache 中顯示遠端的檔案列表, 應該算是 ls 的加強版, 有很多參數可用,應該是可用來產生各種不同>的檔案列表以供其他程式使用。
recls 則不會從 cache 中讀取
du options

計算遠端整個目錄佔用容量
get OPTS -o

抓取遠端檔案 清晰網
get rfile -o lfile

抓 rfile 到本地改名為 lfile
-c 為續傳
-E 抓檔完成後, 將遠端的檔案砍了
-a 為 ascii mode, 預設為 binary mode
-O 設定 base directory 為本地端放檔案的目錄

mget OPTS

下載遠端檔案(可用 wildcard expansion 也就是 *)
pget OPTS -o

使用多個連結來下載檔案, 預設為五個。
-n 3 為三個連結
jobs -v

顯示目前有那些程序在背景執行
-v 顯示詳細的資訊(-v 可多加幾個來顯示更詳細的資訊)
lcd

切換本地端的目錄
mirror OPTS remote [local]

下載整個目錄(樓上的 get 只能用來抓檔案)
-c 續傳
-e 這個要小心一些, 比較遠端和本地端的檔案, 假如遠端沒有的, 就將本地端的檔案刪除, 也就是將本地端和遠端資料同步。
-R 上傳整個目錄
-n 只下載較新的檔案
-r 不用遞回到目錄中
--parallel=n 同時下載 n 個檔案(預設一次只下載一個)清晰網

module name args

載入模組
put OPTS -o

上傳檔案
mput OPTS

上傳檔案(可用 wildcard expansion 也就是 *)
mv

將遠端的 file1 改名為 file2
mrm

用 wildcard expansion 方式來刪除遠端檔案
open OPTS

開啟某個站台
open -u , -p site

queue OPTS []

將 cmd 放到佇列中等待執行
-d index 將編號為 index 的 job 刪除
-m index new_index 將編號為 index 的 job 移至編號 new_index, 插隊專用。
-n index 在編號 index 之前新增一個 job

wait []

將背景執行中的程序移至前景(也可用 fg)
kill all|

刪除全部的 jobs 或 job_no
repeat delay command

每隔 delay 秒, 重覆執行 command, 預設是每隔一秒
rm -r -f

移除遠端檔案
mkdir -p

建立遠端目錄
rmdir -f

移除遠端目錄
set OPT []

設定變數
直接鍵入 set 可看目前定義了那些變數
source

讀取 file, 並執行 file 中的命令(應該是和 bash 中的 source 命令是一樣的吧)
debug [|off] -o

設定 debug level 為 level
-o 將輸出導向至 file
exit [|bg]

結束 lftp
此時若還有 jobs, 則會將 lftp 放至背景執行, 繼續未完成的工作
history -w file-r file-c|-l cnt

和 bash 中的 history 功能一樣
renlist []

只顯示遠端的檔名
pwd -p

顯示目前遠端所在目錄
-p 連登入密碼也顯示
scache []

只打 scache 顯示目前所有的 session, 加上 session_no 可切換至其他的 session,
對於同時開啟多個站台或同個站台不同目錄間切換。


原文出處:linux ftp shell命令 - LINUX - 厦门大学数据挖掘研究组论坛 - Powered by Discuz!
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼] FTP 自動化上傳的 Shell 腳本
【Linux】FTP自動化上傳的Shell腳本
2010年12月29日 晴楓
新建腳本文件upload.sh,腳本內容如下:
#!/bin/sh
lftp 10.12.132.53 <<EOF
login user1 password1
cd subdir
put file1 file2 file3
exit
EOF

以後只需在shell中執行sh upload.sh就可以完成文件上傳了。

另外再配合crontab設置計劃任務可以實現定時上傳文件。


原文出處:枫芸志 » 【Linux】FTP自动化上传的Shell脚本
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]在 Linux 底下使用 FTP 批次指令碼(Using FTP Shell Scripts)
在 Linux 底下使用 FTP 批次指令碼(Using FTP Shell Scripts)

Linux 的 FTP 自動化指令碼,就不需要像 Windows 要建立一個執行命令的文字檔,直接寫在 bash 裡面即可:
#!/bin/bash
#
#
#
ftp -n 192.168.0.50 << EOF
user jeff p@ssw0rd
bi
get list
quit
EOF


我是用 CentOS 4.5 執行該 Shell script,去存取 vsftpd 的時候,會出現下列的訊息:
Please login with USER and PASS.
Please login with USER and PASS.
KERBEROS_V4 rejected as an authentication type

一開始還以為是有問題,後來才知道原本就有這個訊息存在。可以不用理會它。

參考:Tutorial on ftp 網路教材

Linux 還可以在家目錄產生一個 .netrc 的檔案,可將帳號、密碼放在其中,避免看 Shell script 檔就可以知道帳號、密碼。而且該檔的存取權限要設成 600 才行,要不然會出現警告訊息。其格式如下:
machine 192.168.0.50 login jeff password p@ssw0rd

以類似 Windows FTP batch scripts 的方式來執行,首先建立一個動作檔,例:action,其內容如下:
bi
get list
bye

然後再使用下列的指令來執行:
ftp 192.168.0.50 < action

這樣就可以成功地完成了。


原文出處:在 Linux 底下使用 FTP 批次指令碼(Using FTP Shell Scripts) @ 暉獲無度的步烙閣 :: 隨意窩 Xuite日誌
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼] Linux shell 中使用 ftp 自動下載上傳文件
Linux shell中使用ftp自動下載上傳文件

FTP自動登錄批量下載文件

從ftp服務器192.168.1.171上的/home/data 到本地的/home/databackup
 
#!/bin/bash
ftp -v -n 192.168.1.171
user guest 123456
binary
cd /home/data
lcd /home/databackup
prompt
mget *
close
bye

 
FTP自動登錄批量上傳文件
 
從ftp服務器192.168.1.171上的/home/data 到本地的/home/databackup
 
#!/bin/bash
ftp -v -n 192.168.1.171 << END
user guest 123456
binary
hash
cd /home/data
lcd /home/databackup
prompt
mput *
bye
END



原文出處:Linux shell中使用ftp自动下载上传文件-Linux频道-中国IT实验室
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]How to use ftp in a shell script

How to use ftp in a shell script


Sometimes I want to FTP a file from one machine to another. Usually, I can do the transfer interactively, but every so often, I would like to have a shell script do the file transfer. This task has eluded me in the past, but I finally figured it out. I've not seen this particular trick documented in the past, so I submit it for your approval.

The Problem

The problem I always encountered in scripting ftp transfers involved getting a password to the ftp server. Typical ftp client programs under Unix, Linux, Solaris and NetBSD all read the ftp password from /dev/tty.

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

The Tricks


Getting the password to the ftp server without having the ftp client program read the password from /dev/tty requires two tricks:

  1. Using the -n option on the ftp client program to prevent the ftp client from trying to log in immediately. That way, the ftp client does not ask for a user ID and password. No use of /dev/tty.
  2. Use the ftp client program command quote to send user ID and password to the ftp server.

You must the token that ends the "here document" ( END_SCRIPT in the example above) at the beginning of a line. Even if the ftpcommand line and the login and transfer script are indented, END_SCRIPTshould appear with the 'E' as the first character of the line.

Further Refinements

The above sh
script will spew lots of ftp client output to standard output. Even if everything works perfectly, the user running the above script will see lots of incomprehensible text scrolling by quite rapidly. One refinement would send output to different places:

ftp -n $HOST > /tmp/ftp.worked 2> /tmp/ftp.failed <<END_SCRIPT

One could further refine error handling by acting on the ftp client program's exit status:

ftp -n $HOST > /tmp/ftp.worked 2> /tmp/ftp.failed <<END_SCRIPT
blah blah
END_SCRIPT
EXITSTATUS=$?
if [ $EXITSTATUS != "0" ]
then
# handle the error...
fi


Except that the above doesn't always work - most FTP clients always exit with a status of 0. This leads to ugly "false negatives": the file transfer fails, but the script doesn't detect the problem.

One way to verify that a file transfer took place - transfer it back:



#!/bin/sh
ftp -n << END_SCRIPT
open $1
user $2 $3
put $4
get $4 retrieval.$$
bye
END_SCRIPT
if [ -f retrieval.$$ ]
then
echo "FTP of $4 to $1 worked"
rm -f retrieval.$$
else
echo "FTP of $4 did not work"
fi

Regular FTPs there and back of large files can consume a lot of time.

Control of ftp by a shell script

One obvious improvement would have the ftp client program controlled by the shell script. I don't think that would comprise an impossible task, but I also don't think that it would have much value. Scripting ftp transfer using expect might cause you less pain.


Alternative #1

I saw a second way of doing this in a usenet article:



#!/bin/sh
USER=userid
PASSWD=userpw
ftp -n f2dev <<SCRIPT
user $USER $PASSWD
binary
get some.file
quit
SCRIPT


It still uses the "-n" trick, but it sends user ID and password in the same "user" command.


Alternative #2

Use a .netrc file

Linux, Unix and BSD users have the alternative of using a .netrcfile. The ftp man page documents the format of .netrc. To accomplish the task of using ftp in a shell script you would have to fill out a .netrc file something like this:




machine something.else.com
login myid
password mypassword


ftp demands that .netrc not have group or world read or write permissions:




$ ls -l .netrc
-rw------- 1 bediger users 51 Dec 16 13:30 .netrc


Using a .netrc file has a few problems that may or may not prevent you from using it.

  • A shell scripkt that does FTP using .netrc is no longer self-contained. You have to keep track of two files, which means that bugs can be less than obvious.
  • ftp reads it's user ID's .netrc. If you develop your script under a given user ID, then put it in production under a second user ID, you have to coordinate .netrc file contents between those two user IDs.

Alternative #3

Apparently, the Ckermit program from Columbia University understands FTP. You could use Ckermit to
script FTP transfers. This looks to have advantages and disadvantages. On the "pro" side, it appears that Ckermit can exit on various errors, like unknown user IDs, or bad passwords. On the "con" side, you have to have Ckermit. I don't recall that it had a too onerous install, but it doesn't come with many Linux distros these days, and it probably doesn't come with any vendor Unix.


$Id$
原文出處:Using ftp in a shell script
冷日
(冷日)
Webmaster
  • 註冊日: 2008/2/19
  • 來自:
  • 發表數: 15771
[轉貼]is there a way of listing the contents of the local directory in ftp?
is there a way of listing the contents of the local directory in ftp?

lcd changes local directories.

and ls lists files on remote directory.

What I would like is lls, to list files on local directory.

Is this possible? I know i can always open another terminal to do this, but I'm lazy!

Yes:
!dir

The ! tells the client to run a local shell command. Tested this using both the Windows and Fedora default ftp clients. Note that the actual command may depend upon your OS, for example !ls may be necessary on other versions of Unix/Linux.

For what it's worth, the ! command is listed in the ftp client's help system:
    ftp> help !
    !               escape to the shell


原文出處:is there a way of listing the contents of the local directory in ftp? - Stack Overflow
前一個主題 | 下一個主題 | 頁首 | | |



Powered by XOOPS 2.0 © 2001-2008 The XOOPS Project|