Mac下使用命令行登陸ftp
最近使用forklift下載服務器pureftp上的東西,總是斷斷續續的,經常下載到99%然后顯示下載失敗,非常不舒服!原以為是forklift的問題,換了transmit發現同樣有這樣的現象。看來是ftp服務器搭的有問題~~不過因為用的不多,目前懶的解決了,暫時用Mac的終端命令來用着。其實效率也是蠻高的哦=。=
默認的本地目錄是home。 輸入help即可獲得所有命令的幫助。
-
連接ftp服務器
man ftp 可以看到有這些信息。
NAME ftp -- Internet file transfer program SYNOPSIS ftp [-46AadefginpRtvV] [-N netrc] [-o output] [-P port] [-q quittime] [-s srcaddr] [-r retry] [-T dir,max[,inc]] [[user@]host [port]] [[user@]host:[path][/]] [file:///path] [ftp://[user[:password]@]host[:port]/path[/][;type=X]] [http://[user[:password]@]host[:port]/path] [...] ftp -u URL file [...]
連接服務器的話基本上就用到上面的訊息了。原本沒有看man手冊,一直使用
ftp user@xxx.com port
每次都要輸入密碼。后來還是用了下面這個更加簡單的
ftp ftp://user:passwd@xxx.com:port
-
瀏覽文件
命令和Windows、Linux的命令基本相同
ftp> cd Documents ftp> ls ftp> dir
-
下載上傳文件
put filename - Upload a file to the server get filename - Download a file from the server mput filename - Put multiple files on the server mget filename - Get multiple files on the server
-
斷開連接
bye:中斷與服務器的連接。
ftp> bye
-
大部分的命令如下,可敲入
man ftp
獲得ls – list the contents of a directory on the FTP server cd – change the working directory on the FTP server pwd – show the current directory on the FTP server get – download files from the FTP server put – upload files to the FTP server account – include a password with your login information bye – terminate an ftp session and close ftp (or use disconnect to simply terminate a session) bell – make a cute sound after each file transfer is done chmod – change permissions delete – your guess is as good as mine (OK, you got me, it’s to delete a file off the server) glob – enable globbing hash – only functional in Amsterdam help – get help lpwd – print the local working directory for transfers mkdir – create folders on the FTP server rmdir – delete folders from the FTP server newer – only get a file if it’s newer (great for scripting synchronizations) nmap – use positional parameters to set filenames passive – use FTP passive mode prompt – allows the use of letters to automate answers to prompts rate – limit the speed of an upload or download
關於ftp,你甚至還可以寫腳本進行文件操作,比如
#!/bin/bash ftp -d krypted.com << ftpEnd prompt cd /Library/WebServer/Documents put “*.html” put “*.php” cd /Library/WebServer/Documents put “*.png” quit ftpEnd #!/bin/bash ftp -d krypted.com << ftpEnd prompt cd /My/Documents get “*.doc” quit ftpEnd
在你的腳本中,可以使用以下幾個字符獲取一些特定的變量:
%/ – the current working directory of the FTP server
%M – the hostname of the FTP server
%m – the hostname only up to the .
%n – the username used for the FTP server
最后有一個問題,為什么老是有不明的人/機器想登陸我的FTP?= =不過自己也是只有使用的時候才會開。