2016-07-02 60 views

回答

0

ftp不理解Windows環境變量。你要生成腳本,每次文件是這樣的:

set file=test 
set ftpscript=%TEMP%\ftp.txt 
echo user> %ftpscript% 
echo password>> %ftpscript% 
echo get %file%>> %ftpscript% 
echo quit>> %ftpscript% 
ftp -s:%ftpscript% IP  

在這裏,我已經定義在臨時目錄中的臨時腳本,所以它不會污染當前目錄。

0

這上傳多發文件的示例:

@echo off 
Title Multiple file Upload by Hackoo on adrive 
Color 0A 
::****** Settings for FTP ************ 
Set FTPSERVER=ftp.adrive.com 
Set USER=Your Login 
Set Password=Your Password 
Set LocalFolder=C:\Hackoo 
Set RemoteFolder=/backupFolder 
::************************************ 
::--- FTP commands below here --- 
> ft.do echo Open %FTPSERVER% 
>> ft.do echo %USER% 
>> ft.do echo %Password% 
>> ft.do echo prompt n 
>> ft.do echo bin 
>> ft.do echo lcd %LocalFolder% 
>> ft.do echo MkDir %RemoteFolder% 
>> ft.do echo cd %RemoteFolder% 
>> ft.do echo mput "*.*" 
>> ft.do echo disconnect 
>> ft.do echo bye 
::************************************ 
ftp -s:ft.do 
del ft.do 
Pause 

批量這樣的例子只是爲了測試,可以從位於公共FTP服務器的文件夾中僅列出文件,如ftp.microsoft.com爲了創建一個list.txt文件來下載它,所以試試看,並告訴我們結果。

@echo off 
mode con cols=85 lines=22 & Color A 
::*********************************** 
Set FTPSERVER=ftp.microsoft.com 
Title Lister les fichiers et les dossiers sur un serveur FTP (%FTPSERVER%) by Hackoo 
Set USER=anonymous 
Set [email protected] 
Set DossierFTP=/bussys/winsock/winsock2/ 
Set DownloadFolder=winsock2 
::******************************************************* 
Goto Lister 
:Lister 
> ft.do echo Open %FTPSERVER% 
>> ft.do echo %USER% 
>> ft.do echo %Password% 
>> ft.do echo prompt n 
>> ft.do echo bin 
>> ft.do echo cd %DossierFTP% 
>> ft.do echo ls -h TLIST.txt 
>> ft.do echo bye 
ftp -s:ft.do 
del ft.do 
CLS 
Color 9B 
echo Download la liste 
pause 
Goto Download 
::********************************************************* 
:Download 
> ft.do echo Open %FTPSERVER% 
>> ft.do echo %USER% 
>> ft.do echo %Password% 
>> ft.do echo prompt n 
>> ft.do echo bin 
>> ft.do echo cd %DossierFTP% 
for /F %%f in (TLIST.txt) do (>> ft.do echo get %%f) 
>> ft.do echo bye 
ftp -s:ft.do 
del ft.do 
CLS 
Color 9A 
pause 
echo Deplacer la liste 
Goto Deplacer 
::********************************************************* 
:Deplacer 
Set Source=%~dp0 
Set Destination=%Source%%DownloadFolder% 
if not exist %DownloadFolder% MD %DownloadFolder% 
for /F %%f in (TLIST.txt) do (move "%Source%%%f" "%Destination%") 
pause 
0

%-artifact在BAT文件中不起作用的原因是該令牌從未被看到和替換過。就像在UNIX shell腳本中一樣,當這些行被收集並標記時,將執行$ -substitutions。由於包含%file%的行被輸入到FTP,因此它被FTP收集和解析,而不是被「DOS」shell收集和解析。

在UNIX中,您可以通過通過FTP傳遞指令來解決此問題。也就是說,雖然這(其中$ 1是在命令行上提供的文件名參數):

ftp << FTP_CMDS 
user joe 
pass joesPassword 
get $1 
quit 
FTP_CMDS 

是行不通的,這:

(echo user joe; 
&nbsp;echo pass joesPassword; 
&nbsp;echo get $1; 
&nbsp;echo quit) | ftp 

會工作。