Stuff about command-line ftp
— Kaushal ModiTo connect to a machine with ip MACHINE, you simply need to enter the below at command-line:
ftp MACHINE
See below for a list of commands you would typically use once you ftp
to a machine.
Basic FTP Commands #
Command | Description |
---|---|
? or help | Get help on FTP commands |
bye or quit | Exit the FTP session |
binary | Set the mode of file transfer to binary |
(Provides less chance of transmission error) | |
cd , ls , mkdir , pwd , rmdir | Unix operations on remote machine |
delete | Unix rm operation on remote machine |
lcd | Unix cd operation on local machine |
put FILE | Copy 1 file from local to remote |
mput FILES (ex: mput * ) | Copy multiple files from local to remote |
get FILE | Copy 1 file from remote to local |
mget FILES (ex: mget* ) | Copy multiple files from remote to local |
Automating FTP logins for specific IPs #
If you find yourself logging into a specific MACHINE too frequently, and if you want to save yourself from having to enter the username and password each time, you can save those credentials to your ~/.netrc
file. See the example at the end of this post.
If that file does not exist, then create it, and remember to set its permission to 600.
touch ~/.netrc
chmod 600 ~/.netrc
If the permissions are not set so, you will get this ftp error:
Error - .netrc file not correct mode.
Remove password or correct mode.
Ignore the credentials in .netrc
#
But at times, you might need to manually log into a machine with a different set of credentials than the one saved in the ~/.netrc
. To do so, run ftp
with the -n
option. And then use the quote USER
and quote PASS
commands to pass in the username and password.
> ftp -n <machine>
ftp> quote USER <username>
ftp> quote PASS <password>
Commenting out stuff in .netrc
#
Unfortunately, .netrc
does not seem to have a comment syntax. But this hack works ..
Using the #
character quickly followed by an FTP command foo (no space, ex: #foo
) is one way to “comment out” lines with valid .netrc keywords.
You cannot have such ‘comments’ after valid .netrc keywords are used.
So if you need to comment out a set of logins and passwords, do that before the first valid set of uncommented login credentials. See below for an example of that.
An Example ~/.netrc
#
#machine foo.bar.com
#login username1
#password pAsSw0rd1
machine foo.bar.com
login username2
password pAsSw0rd2
References #
- Basic FTP Commands - Colorado State Univerity
- Use configuration file for ftp with auto login enabled upon initial connection - unix.stackexchange
man ftp
,man netrc