如何在C/C++中异步使用ftp?
如何在Shell中使用ftp?
ftp的主要参数是什么?
本文将为你讲述。
How do I ftp a file from a shell script?
A quick little shell script to FTP a file. I built it to do automatic backups with cron.
I'm posting here because it took me a while to figure it out. I hope it's userful for others.
The Code
#!/bin/bash
filename="/home/paul/myfile.tar.gz"
hostname=""
username="username"
password="password"
ftp -un $hostname <<EOF
quote USER $username
quote PASS $password
binary
put $filename
quit
EOF
Pleaes leave feedback about your experience here, thank you.
Update:A reader posted on my blog that he had to change the switch on the ftp command from u to i for his situation.
For those interested, more information on the ftp command can be found on the man page. Most *nix
distros should provide this information with man ftp or info ftp.
From:http://willcode4beer.com/tips.jsp?set=bashftp
FTP
Section: User Commands(1)
NAME
ftp - ARPANET file transfer program
SYNOPSIS
ftp [-v] [-d] [-i] [-n] [-g] [-k realm] [-f] [-x] [-u] [-t] [host]
DESCRIPTION
FTP is the user interface to the ARPANET standard File Transfer Protocol. The program allows a user
to transfer files to and from a remote network site.
OPTIONS
Options may be specified at the command line, or to the command interpreter.
-v Verbose option forces ftp to show all responses from the remote server, as well as report on
data transfer statistics.
-n Restrains ftp from attempting ''auto-login'' upon initial connection. If auto-login is enabled, ftp
will check the .netrc (see below) file in the user's home directory for an entry describing an
account on the remote machine. If no entry exists, ftp will prompt for the remote machine login
name (default is the user identity on the local machine), and, if necessary, prompt for a
password and an account with which to login.
-u Restrains ftp from attempting "auto-authentication" upon initial connection. If auto-
authentication is enabled, ftp attempts to authenticate to the FTP server by sending the AUTH
command, using whichever authentication types are locally supported. Once an authentication
type is accepted, an authentication protocol will proceed by issuing ADAT commands. This option
also disables auto-login.
-i Turns off interactive prompting during multiple file transfters.
-d Enables debugging
-g Disables file name globbing
-k realm
When using keberos v4 authentication, get tickets in realm.
-f Cause credentials to be forwarded to the remote host.
-x Causes the client to attempt to negotiate encryption (data and command protection levels
"private") immediately after successfully aautheticating.
-t Enables packet tracing.
















