- linux登入ftp命令:
ftp ip地址
示例:ftp 101.37.14.146
- 关闭被动模式(被动模式就是服务端给客户端说准备好了)
ftp> passive
Passive mode off.
- 配置文件vsftpd.conf设置客户端最大连接数:
max_per_ip = 5
- 查看ftp服务端当前目录文件和路径:
ls
pwd
- 切换本地目录:
lcd
- 关闭交互模式:
prompt
- 上传一个文件 和多个文件:
ftp> put av2_201017_12_000
ftp> mput av2_201018_* (可以使用通配)
- 下载一个和多个文件:
ftp> get av2_201017_12_000
ftp> mget av2_201018_12*
- 删除文件和目录:
ftp> delete av2_201017_12_000
ftp> rmdir 2
- python 函数关闭被动模式:
ftplib.FTP.set_pasv
ftp下载文件python脚本
#!/usr/bin/python
import ftplib
import os
import socket
HOST = '101.37.14.146'
DIRN = '/home/ftpadmin'
FILE = 'av2_201018_12_192'
def main():
try:
f = ftplib.FTP(HOST)
except:
print 'HOST IS ERROR.'
try:
f.login('ftpadmin','123457')
except:
print 'ERROR: cannot login user for ftpadmin'
f.quit()
print '*** Logged in as "ftpadmin"'
f.set_pasv(False) #关闭被动模式
try :
f.cwd(DIRN)
except:
print 'ERROR: cannot CD TO ' + DIRN
print "CD IS OK"
try:
f.retrbinary('RETR %s' % FILE, open(FILE, 'wb').write)
except:
print 'ERROR: download bad'
os.unlink(FILE)
else:
print '*** download "%s" to CWD' % FILE
f.quit
if __name__ == '__main__':
main()