• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

use a text-base ftp

发布: 2007-6-21 12:06 | 作者:   | 来源:   | 查看: 17次 | 进入软件测试论坛讨论

领测软件测试网

   


  Using a text based ftp client is not truly linux specific, however there is a chance that you may need to download a file from an ftp server and don't want the overhead of installing a GUI based ftp client nor using a comparitively bloated webbrowser. Maybe you want to use some of the power and features available in a ftp client that for whatever reasons aren't supported in the webbrowsers.
Most text based ftp clients, regardless of the operating system they run on, use the same command set that you type in to instruct the client on what it is you want it to do - generally speaking you should be able to learn how to use a text based ftp client once and use that knowledge many times. I'm writing this under the assumption that you are using linux to connect to ftp servers.


1. Logging in.
Firstly you will need to open a connection to the ftp server:


$ftp
ftp> open edge

This opens a connection to the ftp server running on my linux box called 'edge' and could also have been done by typing
$ftp edge
After the client has connected to the server you will see a login banner and a username prompt. After typing in the user name you will be prompted for a password - if you want to log in to an 'anonymous' account you should enter youremail address as the password.
To log out, type 'quit'.
If you use ncftp as the ftp client and it has automatic anonymous logins enabled (which it does by default), then you won't be prompted for a username amd password.


2. Directories.
2.1 Initial directory.
If you log in as anonymous then your initial working directory will be the root dierctory, otherwise your initial working directory will be the home directory of the user that you logged in as.
2.2 Changing directories:
You will need to move to the appropiate directory once you have logged in. Doing this is the very same as changing directories within linux - with the 'cd' command. Using 'cd' will move you around the directory structure of the ftp server, if you need to move around the directories of the PC that you are connecting with, then you should use the 'lcd' command.
Depending on which operating system the ftp server is running on it will most likly be case sensitive with regards to file and directory names.
2.3 Directory Listings.
As with Unix, the 'ls' command should be used if you want to get a general listing of what files are in the remote working directory.
There's a particular twist though, if you want a 'long' directory listing similar to what you get with 'ls -l' you can either type 'ls -l' itself or be slightly lazy about it and type 'dir'.
If you would like to keep a local copy of the directory listing, the 'mls' command should be used.
With regard to using mls, you have to specify which remote directory the listing should be of, so if you want a listing of the current directory you have to type '.' as the name of the directory.
You then have to specify the local file that you want the directory listing to be saved to and type 'y' in response to the 'output to local file' question that follows.
2.4 Modification date of a file.
The 'modtime' command is useful for when you need to know when a remote file was last modified.


3. Running a 'shell' command.
It can be useful at times to run a shell command from within an ftp connection. This is done by first typing an exclamation mark (!) followed by the command itself.
I do this quite often to ensure that I am in the correct local directory as it helps to make certain that I am not going to to overwrite a local file. To do this, you should type:

ftp> !pwd /home/ken
You can also use '!' on it's own to get to the command prompt without logging out from the ftp session. You can get back to the ftp prompt by typing 'exit'.


4. Transferring files.
Okay, so now that you know how to log in and change directories the next thing that you need to learn is how to transfer files.
Before you get around to transferring a file though it is important that you are in the correct transfer type.
4.1 Transfer type.
There are two transfer types that can be used to transfer files; ascii and binary.
To see which transfer type is currently active, use the 'type' command.

ftp> type
Using binary mode to transfer files.
ftp> ascii
200 Type set to A.
ftp> type
Using ascii mode to transfer files.
ftp> binary
200 Type set to I.
ftp> type
Using binary mode to transfer files.

As seen in the example above, type 'ascii' to change to the ascii type and 'binary' to change to the binary type.
4.2 Copying files.
To get a copy of a file from the server to the local computer you use the command 'get'.
Tp put a copy of a local file onto the sever you use the command 'put'.
4.3 Copying multiple files.
If you need to copy a number of files of the same transfer type from one remote directory to a local directory you can use the command 'mget', similarly 'mput' should be used to transfer a number of files of the same type onto the server.
You can be as specific or as general in your use of 'mget' or 'mput' as you like.
For example 'mget *' means that all remote files (both binary and ascii) will get copied down from the server. Similarly 'mget foo*' means that all files starting with 'foo' will be copied down from the server.
Each time that you use mget or mput you will be prompted to confirm the transfer. Typing anything other than 'n' means the file will be copied.
You can quit out of mget or mput and remain in the ftp session by pressing ctrl-c.
4.4 Resuming a 'get'.
One of the nice advantages that you get by using an ftp client over a web browser that supports the ftp protocol is that, if your connection to the server breaks for whatever reason, you can get the ftp client to start over again from where it left off. This is done by using the 'reget' command.


4.5 Visual confirmation.
If you are copying a large file and would like some form of visual indication of progress then the 'hash' command, which causes the hash mark (#) to be printed for each segment of the file which has been copied, will be of use to you.
You should use the 'hash' command before copying the file for which you want the visual indication.


5. Deleting files.
Once you have made a local copy of a file from the server you may want to delete the original file that you copied. Naturally, this will only work if you have the appropriate permissions to delete the file.
To do this, use the 'delete' command.
if you have a number of files to delete, I'd suggest you use the 'mdelete' command which can be aborted by pressing ctrl-c.


6. Macros.
I doubt this facility is available in all text based ftp clients but it is far too useful to not mention.
You can use 'macdef' to combine several commands into a macro, so that for example if you find that you always follow a 'pwd' with a '!pwd' then you could combine these into a macro called '2pwd' and use that instead. For example:


ftp> macdef 2pwd
Enter macro line by line, terminating it with a null line
pwd
!pwd
<Enter>
To indicate that you want to use a macro instead of a standard command you have to preceed the name of the macro with a dollar sign ($). For example:
ftp> $2pwd
pwd
257 "/home2/wolfhaven" is current directory.
!pwd
/home/ken

This is a very trivial example but you should be able to see how to apply this to a larger sequence of commands.
X. More Information.
If you would like to learn more of the ftp client's commands, I'd suggest you use the help command and also man ftp at the command prompt. Using 'help' on its own will present you with a list of commands that the ftp client supports, to get details of what a specific command does then add it as a parameter to the help command. For example:

ftp> help verbose
verbose toggle verbose mode

延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网